diff --git a/CHANGES b/CHANGES index 7b53a53..65f459a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,10 +1,11 @@ -0.3.2 2022-12-20 11:07:44 +0100 Tobias Bossert - - - - -0.3.2 2022-12-20 Tobias Bossert (tobib at cpan.org) +0.3.3 2022-12-20 Tobias Bossert (tobib at cpan.org) - Fixed dead lock in some situations when a reload callback is called +0.3.2 2021-12-10 Tobias Bossert (tobib at cpan.org) +- added: CLI: Support for DNS hostname and endpoint FQDN +- changed: CLI: wg-meta show output is now easier to read +- fix: PresistentKeepalive -> PersistentKeepalive Resolves #15 + 0.3.1 2021-07-06 Tobias Bossert (tobib at cpan.org) - Improved doc - fix: concurrency test -> added small delay between writes diff --git a/COPYRIGHT b/COPYRIGHT index 0a8ab3e..22401f7 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,6 +1,6 @@ wg-meta -Copyright (c) 2020 Tobias Bossert and the other people listed in the +Copyright (c) 2021 Tobias Bossert and the other people listed in the AUTHORS file. All rights reserved. diff --git a/LICENSE b/LICENSE index ceac5bc..5da450d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Tobias Bossert +Copyright (c) 2021 Tobias Bossert Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index e05feba..25b0ded 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,23 @@ sudo wg-meta enable wg0 WG_0_PEER_A_PUBLIC_KEY # Apply config sudo wg-meta apply wg0 +# Add new peer +# Note: To automatically set the DNS and endpoint address, make sure you add #+DNSHost and #+FQDN to your hosts interface config +wg-meta addpeer wg0 10.60.0.10 alias tobi_laptop + +[Interface] +Address = 10.60.0.10 +ListenPort = 44544 +PrivateKey = PEER_PRIVATE_KEY +DNS = 10.20.0.1 +#+Alias = tobi_laptop + +[Peer] +PublicKey = HOST_PUBLIC_KEY +AllowedIPs = 0.0.0.0/0, ::/0 +Endpoint = your.fqdn.con:51888 +PersistentKeepalive = 25 + ``` @@ -132,5 +149,5 @@ AllowedIPs = fdc9:281f:04d7:9ee9::1/128 Endpoint = wg.example.com ``` -Development of this project is sponsored by [OETIKER+PARTNER AG](https://oetiker.ch) +Initial development of this project is sponsored by [OETIKER+PARTNER AG](https://oetiker.ch) diff --git a/lib/Wireguard/WGmeta.pm b/lib/Wireguard/WGmeta.pm index a888a95..5ae379d 100644 --- a/lib/Wireguard/WGmeta.pm +++ b/lib/Wireguard/WGmeta.pm @@ -40,7 +40,7 @@ L for sponsoring this project. MIT License -Copyright (c) 2020 Tobias Bossert +Copyright (c) 2021 Tobias Bossert Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/Wireguard/WGmeta/Cli/Commands/Add.pm b/lib/Wireguard/WGmeta/Cli/Commands/Add.pm index 218d2da..b5a2867 100644 --- a/lib/Wireguard/WGmeta/Cli/Commands/Add.pm +++ b/lib/Wireguard/WGmeta/Cli/Commands/Add.pm @@ -43,10 +43,17 @@ sub _run_command($self) { # get pubkey of iface priv-key my $iface_pubkey = get_pub_key($iface_privkey); + # get interface config + my %host_interface = $self->wg_meta->get_interface_section($self->{interface}, $self->{interface}); + my $fqdn = exists($host_interface{FQDN}) ? $host_interface{FQDN} : 'insert.valid.fqdn.not.valid'; + # lets create a temporary interface $self->wg_meta->add_interface('temp', $self->{ips}, 44544, $self->{priv_key}); $self->wg_meta->add_peer('temp', '0.0.0.0/0, ::/0', $iface_pubkey); - $self->wg_meta->set('temp', $iface_pubkey, 'endpoint', "insert.valid.fqdn.not.valid:$iface_listen"); + $self->wg_meta->set('temp', $iface_pubkey, 'endpoint', "$fqdn:$iface_listen"); + if (exists($host_interface{DNSHost})){ + $self->wg_meta->set('temp', 'temp', 'dns', $host_interface{DNSHost}); + } $self->wg_meta->set('temp', $iface_pubkey, 'persistent-keepalive', 25); my $unknown_handler_temp = sub($attribute, $value) { @@ -85,7 +92,8 @@ sub cmd_help($self) { print "Usage: wg-meta addpeer [attr1 value1] [attr2 value2] ...\n\n" . "Notes: \nAttributes meant to reside in the [Interface] section are only applied to the peer's interface\n" . "wg-meta attributes are applied to the host's peer config and the client interface config\n" - . "and finally, attributes meant to be in the [Peer] section are only applied to the host's peer entry\n\n" + . "and finally, attributes meant to be in the [Peer] section are only applied to the host's peer entry.\n\n" + . "To automatically fill in dns and endpoint name, make sure #+DNSHost and #+FQDN is present in [Interface]\n" . "Do not forget to reload the configuration afterwards!\n"; exit(); diff --git a/lib/Wireguard/WGmeta/Cli/Commands/Show.pm b/lib/Wireguard/WGmeta/Cli/Commands/Show.pm index 12de6dc..3176eaf 100644 --- a/lib/Wireguard/WGmeta/Cli/Commands/Show.pm +++ b/lib/Wireguard/WGmeta/Cli/Commands/Show.pm @@ -130,9 +130,8 @@ sub _run_command($self, $interface, $is_dump, $ref_attr_list) { $state = ($interface_is_active and keys %wg_show_section > 1) ? 1 : 0; my $state_marker = ($state == 1) ? BOLD . GREEN . '●' . RESET : BOLD . RED . '●' . RESET; $output .= $state_marker . BOLD . lc($type) . ": " . RESET . $identifier . "\n"; - $output .= $self->_get_pretty_line(\%config_section, \%wg_show_section, $ref_attr_list) . "\n"; + $output .= $self->_get_pretty_line(\%config_section, \%wg_show_section, $ref_attr_list) . "\n\n"; } - } } print $output; diff --git a/lib/Wireguard/WGmeta/ValidAttributes.pm b/lib/Wireguard/WGmeta/ValidAttributes.pm index 0a1ca6c..1546739 100644 --- a/lib/Wireguard/WGmeta/ValidAttributes.pm +++ b/lib/Wireguard/WGmeta/ValidAttributes.pm @@ -179,7 +179,7 @@ use constant KNOWN_ATTRIBUTES => { 'validator' => \&accept_any }, 'persistent-keepalive' => { - 'in_config_name' => 'PresistentKeepalive', + 'in_config_name' => 'PersistentKeepalive', 'type' => ATTR_TYPE_IS_WG_ORIG_PEER, 'validator' => \&accept_any }, diff --git a/lib/Wireguard/WGmeta/Wrapper/Config.pm b/lib/Wireguard/WGmeta/Wrapper/Config.pm index 03d9cde..a1f8350 100644 --- a/lib/Wireguard/WGmeta/Wrapper/Config.pm +++ b/lib/Wireguard/WGmeta/Wrapper/Config.pm @@ -216,7 +216,7 @@ sub set($self, $interface, $identifier, $attribute, $value, $unknown_callback = die "Attribute `$attribute` it not valid for the interface section" if $attr_type == ATTR_TYPE_IS_WG_ORIG_PEER; } else { - die "Attribute `$attribute` is not valid for an peer section" if $attr_type == ATTR_TYPE_IS_WG_ORIG_INTERFACE or $attr_type == ATTR_TYPE_IS_WG_QUICK; + die "Attribute `$attribute` is not valid for a peer section" if $attr_type == ATTR_TYPE_IS_WG_ORIG_INTERFACE or $attr_type == ATTR_TYPE_IS_WG_QUICK; } # skip if same value