Skip to content

Commit

Permalink
version++
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtoobii committed Jul 2, 2021
1 parent 0cc15d5 commit bb1af90
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .debian/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: wg-meta
Version: 0.0.3
Version: 0.3.0
Section: base
Priority: optional
Architecture: all
Expand Down
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
0.3.0 2021-07-03 Tobias Bossert (tobib at cpan.org)
- changed: CLI: Seamless support for custom attributes (set and addpeer)
- added: CLI: Ability to remove peers
- added: CLI: Machine readable output (dump)
- changed: Core: removed any predefined wg-meta attributes (except alias and checksum)
- changed: Core: Rewrote parser architecture to be more general and extendable
- changed: Tests: Are now not dependent on threads any more
- changed: Wrapper: API of set() and add_peer()

0.2.3 2021-04-15 Tobias Bossert (tobib at cpan.org)
- changed: Commit behaviour when set to overwrite = False
- changed: Adding custom attributes is now possible in code
Expand Down
10 changes: 6 additions & 4 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ AUTHORS
bin/wg-meta
CHANGES
COPYRIGHT
dist.sh
lib/Wireguard/WGmeta.pm
lib/Wireguard/WGmeta/Cli/Commands/Add.pm
lib/Wireguard/WGmeta/Cli/Commands/Apply.pm
lib/Wireguard/WGmeta/Cli/Commands/Command.pm
lib/Wireguard/WGmeta/Cli/Commands/Disable.pm
lib/Wireguard/WGmeta/Cli/Commands/Enable.pm
lib/Wireguard/WGmeta/Cli/Commands/Help.pm
lib/Wireguard/WGmeta/Cli/Commands/Remove.pm
lib/Wireguard/WGmeta/Cli/Commands/Set.pm
lib/Wireguard/WGmeta/Cli/Commands/Show.pm
lib/Wireguard/WGmeta/Cli/Human.pm
lib/Wireguard/WGmeta/Cli/Router.pm
lib/Wireguard/WGmeta/Cli/TerminalHelpers.pm
lib/Wireguard/WGmeta/Index.pod
lib/Wireguard/WGmeta/Parser/Config.pm
lib/Wireguard/WGmeta/Parser/Conf.pm
lib/Wireguard/WGmeta/Parser/Middleware.pm
lib/Wireguard/WGmeta/Parser/Show.pm
lib/Wireguard/WGmeta/Utils.pm
lib/Wireguard/WGmeta/Validator.pm
Expand All @@ -42,7 +43,8 @@ t/test_data/mini_wg0.conf_skip
t/test_data/mini_wg1.conf
t/test_data/not_a_wg_config.conf
t/test_data/wg_show_dump
t/wrapper_test.t
t/wrapper_custom_attrs.t
t/wrapper_secure_mode.t
t/wrapper_test.t
VERSION
wg-meta_completions.sh
wg-meta_completions.sh
2 changes: 2 additions & 0 deletions MANIFEST.SKIP
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ cpanfile
\.perl-version
configure\.ac
^_Deparsed_XSubs\.pm
dist.sh
MANIFEST.bak
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.3
0.3.0
15 changes: 7 additions & 8 deletions bin/wg-meta
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ use experimental 'signatures';
use Wireguard::WGmeta::Cli::Router;
use Wireguard::WGmeta::Cli::TerminalHelpers;

our $VERSION = "0.0.0";
our $VERSION = "0.3.0";

local $SIG{__WARN__} = sub($message) {
prettify_message($message, 1);
Expand All @@ -131,12 +131,11 @@ if (@ARGV && $ARGV[0] eq '--version') {
}

# command line argument parser
route_command(\@ARGV);
# eval {
# route_command(\@ARGV);
# };
# if ($@) {
# prettify_message($@, 0);
# }
eval {
route_command(\@ARGV);
};
if ($@) {
prettify_message($@, 0);
}


2 changes: 1 addition & 1 deletion lib/Wireguard/WGmeta.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ use strict;
use warnings FATAL => 'all';
package Wireguard::WGmeta;

our $VERSION = "0.0.0"; # Do not change manually
our $VERSION = "0.3.0"; # Do not change manually

1;
8 changes: 4 additions & 4 deletions lib/Wireguard/WGmeta/Cli/Commands/Add.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ sub _run_command($self) {
# 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_fqdn>:$iface_listen");
$self->wg_meta->set('temp', $iface_pubkey, 'endpoint', "insert.valid.fqdn.not.valid:$iface_listen");
$self->wg_meta->set('temp', $iface_pubkey, 'persistent-keepalive', 25);

my $unknown_handler_temp = sub($attribute, $value) {
Expand Down Expand Up @@ -78,15 +78,15 @@ sub _run_command($self) {
print "#Generated by wg-meta\n" . $self->wg_meta->create_config('temp', 0);
# remove our temp interface again
$self->wg_meta->remove_interface('temp');

$self->{wg_meta}->commit(1);
$self->wg_meta->commit(1);
}

sub cmd_help($self) {
print "Usage: wg-meta addpeer <interface> <ip-address> [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";
. "and finally, attributes meant to be in the [Peer] section are only applied to the host's peer entry\n\n"
. "Do not forget to reload the configuration afterwards!\n";

exit();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Wireguard/WGmeta/Cli/Commands/Apply.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ sub _run_command($self) {

# please note that there ar potential problems with this commend as mentioned here: https://github.com/WireGuard/wireguard-tools/pull/3
my $cmd_line = "su -c 'wg syncconf $interface <(wg-quick strip $interface)'";
unless (defined $ENV{WG_META_NO_WG}) {
unless (defined $ENV{WGmeta_NO_WG}) {
run_external($cmd_line);
} else {
print "Faked apply \n";
}
print "Faked apply \n";

}

sub cmd_help($self) {
Expand Down
3 changes: 2 additions & 1 deletion lib/Wireguard/WGmeta/Cli/Commands/Set.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ sub _apply_change_set($self, $interface, @change_set) {
}
sub cmd_help($self) {
print "Usage: wg-meta set <interface> [attr1 value1] [attr2 value2] [peer {alias|public-key}] [attr1 value1] [attr2 value2] ...\n\n"
. "Notes:\n The interface aims to follow the official `wg set` specification\n";
. "Notes:\n The interface aims to follow the official `wg set` specification\n"
. "To introduce new attributes prefix them with `+`";
}

sub _set_values($self, $interface, $identifier, $ref_hash_values) {
Expand Down
9 changes: 8 additions & 1 deletion lib/Wireguard/WGmeta/Cli/Commands/Show.pm
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ sub _run_command($self, $interface, $is_dump, $ref_attr_list) {
}
else {
$identifier = $config_section{'alias'} if exists $config_section{'alias'};
$state = ($config_section{'disabled'} == 0 and $interface_is_active) ? 1 : 0;

# we only show a green dot when the peer appears in the show output
$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";
Expand Down Expand Up @@ -191,6 +193,11 @@ sub _get_dump_line($self, $ref_config_section, $ref_show_section, $ref_attr_list

sub cmd_help($self) {
print "Usage: wg-meta show {interface|all} [attribute1, attribute2, ...] [dump] \n"
. "Notes:\n"
. "A green dot indicates an interface/peer's 'real' state which means that its currently possible\n"
. "to connect to this interface/peer.\n"
. "A red dot on the other hand indicates that its not possible to connect. This could mean not applied changes, \n"
. "a disabled peer or the parent interface is down. \n"
}

1;
13 changes: 9 additions & 4 deletions lib/Wireguard/WGmeta/Cli/Human.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package Wireguard::WGmeta::Cli::Human;
use strict;
use warnings FATAL => 'all';
use experimental 'signatures';
use Scalar::Util qw(looks_like_number);
use base 'Exporter';
our @EXPORT = qw(disabled2human bits2human return_self timestamp2human);

Expand Down Expand Up @@ -42,8 +43,12 @@ $n_bits * 1_000_000 . "MiB"
=cut
sub bits2human($n_bits) {
# this calculation is probably not correct, however, I found no reference on what is actually the unit of the wg show dump...
return sprintf("%.2f %s", $n_bits / 1_000_000, "MiB");
if (looks_like_number($n_bits)){
# this calculation is probably not correct, however, I found no reference on what is actually the unit of the wg show dump...
return sprintf("%.2f %s", $n_bits / 1_000_000, "MiB");
}
return "0.0 MiB";

}

=head3 timestamp2human($timestamp)
Expand All @@ -66,10 +71,10 @@ A string describing how long ago this timestamp was
=cut
sub timestamp2human($timestamp) {
my $int_timestamp = int($timestamp);
if ($int_timestamp == 0) {
if (not looks_like_number($timestamp) or $timestamp == 0) {
return "never"
}
my $int_timestamp = int($timestamp);
my $delta = time - $int_timestamp;
if ($delta > 2592000) {
return ">month ago";
Expand Down
2 changes: 1 addition & 1 deletion lib/Wireguard/WGmeta/Cli/Router.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use Wireguard::WGmeta::Cli::Commands::Remove;
use base 'Exporter';
our @EXPORT = qw(route_command);

our $VERSION = "0.0.0";
our $VERSION = "0.3.0";

=head2 route_command($ref_list_input_args)
Expand Down
2 changes: 1 addition & 1 deletion lib/Wireguard/WGmeta/Parser/Conf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use constant INTERNAL_KEY_PREFIX => 'int_';
use base 'Exporter';
our @EXPORT = qw(parse_raw_wg_config INTERNAL_KEY_PREFIX);

our $VERSION = "0.0.0";
our $VERSION = "0.3.0";

=head3 parse_raw_wg_config($file_content, $on_every_value, $on_new_section [, $skip, $wg_meta_prefix, $wg_disabled_prefix])
Expand Down
6 changes: 3 additions & 3 deletions lib/Wireguard/WGmeta/Parser/Middleware.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
=head1 NAME
WGmeta::Parser::Middleware - Middleware between the parser and wrapper classe(s)
WGmeta::Parser::Middleware - Middleware between the parser and wrapper class(es)
=head1 SYNOPSIS
Expand Down Expand Up @@ -36,7 +36,7 @@ use Wireguard::WGmeta::Utils;
use base 'Exporter';
our @EXPORT = qw(parse_wg_config2 create_wg_config2);

our $VERSION = "0.0.0";
our $VERSION = "0.3.0";

=head3 parse_wg_config2($config_file_content, $interface_name [, $wg_meta_prefix, $disabled_prefix, $use_checksum])
Expand Down Expand Up @@ -266,7 +266,7 @@ sub create_wg_config2($ref_interface_config, $wg_meta_prefix = '#+', $disabled_p
$new_config .= _write_line($identifier, $ref_interface_config->{$identifier}, '', $wg_meta_prefix);
}
else {
# First lets check if the following section is active'int_disabled'
# First lets check if the following section is active
my $is_disabled = (exists $ref_interface_config->{$identifier}{'disabled'}
and $ref_interface_config->{$identifier}{'disabled'} == 1) ? $disabled_prefix : '';

Expand Down
5 changes: 2 additions & 3 deletions lib/Wireguard/WGmeta/Parser/Show.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ use experimental 'signatures';
use base 'Exporter';
our @EXPORT = qw(wg_show_dump_parser);

our $VERSION = "0.0.0"; # do not change manually, this variable is updated when calling make
our $VERSION = "0.3.0"; # do not change manually, this variable is updated when calling make


=head3 wg_show_dump_parser($input)
Parser for the output of C<wg show dump>. Aims to be produce a similar structure as
L<Wireguard::WGmeta::Parser::Config/parse_wg_config($config_file_content, $interface_name, $wg_meta_prefix, $disabled_prefix [, $use_checksum])>:
Parser for the output of C<wg show dump>:
{
'interface_name' => {
Expand Down
4 changes: 2 additions & 2 deletions lib/Wireguard/WGmeta/ValidAttributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use experimental 'signatures';

use Wireguard::WGmeta::Validator;

our $VERSION = "0.0.0";
our $VERSION = "0.3.0";

=head1 ATTRIBUTE TYPES
Expand Down Expand Up @@ -179,7 +179,7 @@ use constant KNOWN_ATTRIBUTES => {
'validator' => \&accept_any
},
'persistent-keepalive' => {
'in_config_name' => 'PresistentKeepAlive',
'in_config_name' => 'PresistentKeepalive',
'type' => ATTR_TYPE_IS_WG_ORIG_PEER,
'validator' => \&accept_any
},
Expand Down
2 changes: 1 addition & 1 deletion lib/Wireguard/WGmeta/Wrapper/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use Wireguard::WGmeta::ValidAttributes;
use Wireguard::WGmeta::Utils;
use Wireguard::WGmeta::Parser::Conf qw(INTERNAL_KEY_PREFIX);

our $VERSION = "0.0.0"; # do not change manually, this variable is updated when calling make
our $VERSION = "0.3.0"; # do not change manually, this variable is updated when calling make

use constant FALSE => 0;
use constant TRUE => 1;
Expand Down
12 changes: 1 addition & 11 deletions lib/Wireguard/WGmeta/Wrapper/ConfigT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ use constant FALSE => 0;
use constant TRUE => 1;
use constant INTEGRITY_HASH_SALT => 'wefnwioefh9032ur3';

our $VERSION = "0.0.0"; # do not change manually, this variable is updated when calling make
our $VERSION = "0.3.0"; # do not change manually, this variable is updated when calling make

=head3 is_valid_interface($interface)
Expand Down Expand Up @@ -190,16 +190,6 @@ sub get_peer_count($self, $interface = undef) {
return $self->SUPER::get_peer_count($interface);
}

=head3 get_peer_count([$interface])
L<Wireguard::WGmeta::Wrapper::Config/get_interface_fqdn($interface)>
=cut
sub get_interface_fqdn($self, $interface) {
$self->may_reload_from_disk($interface);
return $self->SUPER::get_interface_fqdn($interface);
}

sub _get_all_conf_files($wireguard_home) {
my @config_files = read_dir($wireguard_home, qr/.*\.conf$/);
if (@config_files == 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Wireguard/WGmeta/Wrapper/Show.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use warnings FATAL => 'all';
use experimental 'signatures';


our $VERSION = "0.0.0";
our $VERSION = "0.3.0";

use constant FALSE => 0;
use constant TRUE => 1;
Expand Down
Loading

0 comments on commit bb1af90

Please sign in to comment.