Skip to content

Commit

Permalink
Merge pull request #10 from oposs/qol_changes
Browse files Browse the repository at this point in the history
correctly sort numbers, send only on success, include email template in pkg
  • Loading branch information
sirtoobii authored Mar 24, 2023
2 parents 227ec26 + 342375f commit d0b5776
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 49 deletions.
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
wg-wrangler (0.3.1) UNRELEASED; urgency=medium

* Sort numeric columns numerically
* Send emails only if everything before successes
* 'Send by Email' is now the default option
* Also show 'Last Handshake' column

-- Tobias Bossert <[email protected]> Fri, 24 Mar 2023 14:57:27 +0100

wg-wrangler (0.3.0) unstable; urgency=medium

* Fixed incorrect handling of #+comment tags
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.0
0.3.1
2 changes: 1 addition & 1 deletion etc/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@


ETC = wgwrangler.dist.yaml env.dist.conf
ETC = wgwrangler.dist.yaml env.dist.conf send_config_by_email.dist.ep
EXTRA_DIST = $(ETC)
sysconf_DATA = $(ETC)
4 changes: 2 additions & 2 deletions etc/wgwrangler.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ BACKEND:
vpn_name: 'Awesome Wireguard VPN'
# Enable versioning for wireguard configurations
enable_git: false
# Instead of applying the configuration automatically after every edit, show a button to apply the configuration manually
no_apply: false
# Instead of applying the configuration automatically after every edit (true) show a button to manually apply the configuration
no_apply: true
not_applied_suffix: .not_applied
# Where does your wireguard configuration reside? (trailing slash expected)
wireguard_home: /etc/wireguard/
Expand Down
29 changes: 19 additions & 10 deletions lib/WGwrangler/GuiPlugin/WireguardAddPeerForm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,15 @@ has formCfg => sub ($self) {
{
key => 'send_by_email',
label => => trm('Send by Email'),
widget => 'checkBox'
widget => 'checkBox',
set => {
value => true
}
},
{
widget => 'header',
label => trm('Note: The configuration rendered in the preview is also completely valid'),
}
];
};

Expand Down Expand Up @@ -316,6 +323,17 @@ has actionCfg => sub ($self) {
$self->app->wireguardModel->update_peer_data($interface, $peer_pub_key, 'device', $device);
$self->app->wireguardModel->update_peer_data($interface, $peer_pub_key, 'created', $created);

# Commit changes
$self->app->wireguardModel->commit_changes({});

# Check into VCS if enabled
if ($self->config->{'no_apply'} && $self->config->{'enable_git'}) {
my $commit_message = "Created peer for `$name` on interface `$interface`";
my $user_string = $self->user->{userInfo}{cbuser_login};
$self->app->versionManager->checkin_new_version($commit_message, $user_string, '[email protected]');
}

# And send mail if no error occurred so far
if (defined $send_by_email && $send_by_email == 1) {
my $email_cfg = {
'name' => $name,
Expand All @@ -335,15 +353,6 @@ has actionCfg => sub ($self) {
};
$self->mailHandler->prepare_and_send($email_cfg);
}
# Commit changes
$self->app->wireguardModel->commit_changes({});

# Check into VCS if enabled
if ($self->config->{'no_apply'} && $self->config->{'enable_git'}) {
my $commit_message = "Created peer for `$name` on interface `$interface`";
my $user_string = $self->user->{userInfo}{cbuser_login};
$self->app->versionManager->checkin_new_version($commit_message, $user_string, '[email protected]');
}
};
if ($@) {
my $error_id = int(rand(100000));
Expand Down
60 changes: 33 additions & 27 deletions lib/WGwrangler/GuiPlugin/WireguardShow.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ has formCfg => sub($self) {
]
};

has tableCfgHash => sub($self) {
# Simply convert the tableCfg to a hash where the 'key'-field becomes the key
my %hash = map {$_->{'key'} => $_} @{$self->tableCfg()};
return \%hash;
};

has tableCfg => sub($self) {
return [
{
Expand Down Expand Up @@ -93,46 +99,44 @@ has tableCfg => sub($self) {
width => '2*',
key => 'transfer-rx',
sortable => true,
# format => {
# unitPrefix => 'metric',
# maximumFractionDigits => 2,
# postfix => 'Byte',
# locale => 'en'
# },
format => {
unitPrefix => 'metric',
maximumFractionDigits => 2,
postfix => 'Byte',
locale => 'en'
},
},
{
label => trm('Transfer-TX'),
type => 'number',
width => '1*',
key => 'transfer-tx',
sortable => true,
# format => {
# unitPrefix => 'metric',
# maximumFractionDigits => 2,
# postfix => 'Byte',
# locale => 'en'
# },
format => {
unitPrefix => 'metric',
maximumFractionDigits => 2,
postfix => 'Byte',
locale => 'en'
},
},
# {
# label => trm('Size'),
# type => 'number',
# format => {
# unitPrefix => 'metric',
# maximumFractionDigits => 2,
# postfix => 'Byte',
# locale => 'en'
# },
# width => '1*',
# key => 'song_size',
# sortable => true,
# },
{
label => trm('Endpoint'),
type => 'string',
width => '3*',
width => '2*',
key => 'endpoint',
sortable => true,
},
{
label => trm('Latest Handshake'),
type => 'number',
width => '1*',
key => 'latest-handshake',
sortable => true,
format => {
postfix => 's',
maximumFractionDigits => 2,
},
},
]
};

Expand Down Expand Up @@ -317,7 +321,9 @@ sub getTableData ($self, $args, $qx_locale) {
my $filter = $args->{formData}{wg_interface};
my $data = $self->app->wireguardModel->get_peer_table_data($args->{firstRow}, $args->{lastRow}, $filter);
if ($args->{sortColumn}) {
$data = $self->app->wireguardModel->sort_table_data($data, $args->{sortColumn}, $args->{sortDesc});
my $table_cfg = $self->tableCfgHash();
my $column_type = $table_cfg->{$args->{sortColumn}}{'type'} // 'string';
$data = $self->app->wireguardModel->sort_table_data($data, $args->{sortColumn}, $args->{sortDesc}, $column_type);
}
# add action set to each row
for my $row (@{$data}) {
Expand Down
2 changes: 1 addition & 1 deletion lib/WGwrangler/GuiPlugin/WireguardVersions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ has actionCfg => sub ($self) {
},
actionHandler => sub ($self, $args) {
my $hash = $args->{selection}{'hash'};
die mkerror(4992, "You have to select a peer first") if not $hash;
die mkerror(4992, "You have to select an entry first") if not $hash;

$self->app->versionManager->go_back_to_revision($hash);

Expand Down
18 changes: 14 additions & 4 deletions lib/WGwrangler/Model/WireguardDataAdapter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ has 'wg_not_installed' => sub {
return defined $ENV{'WGwrangler_NO_WG'}
};

has 'wg_meta' => sub ($self) {
has 'wg_meta' => sub($self) {
my $custom_attr_config = {
'email' => {
'validator' => sub($value) {return $value =~ /^\S+@\S+\.\S+$/;}
Expand Down Expand Up @@ -250,14 +250,24 @@ sub commit_changes ($self, $ref_integrity_hashes) {
$self->apply_config() if $self->is_hot_config;
}

sub sort_table_data ($self, $data, $key, $order) {
sub sort_table_data ($self, $data, $key, $order, $data_type) {
my @keys_to_sort = map {$_->{$key}} @{$data};
my @sorted_indexes;
if (defined $order) {
@sorted_indexes = sort {($keys_to_sort[$b] // '') cmp ($keys_to_sort[$a] // '')} 0 .. $#keys_to_sort;
if ($data_type eq 'number') {
@sorted_indexes = sort {($keys_to_sort[$b] // 0) <=> ($keys_to_sort[$a] // 0)} 0 .. $#keys_to_sort;
}
else {
@sorted_indexes = sort {($keys_to_sort[$b] // '') cmp ($keys_to_sort[$a] // '')} 0 .. $#keys_to_sort;
}
}
else {
@sorted_indexes = sort {($keys_to_sort[$a] // '') cmp ($keys_to_sort[$b] // '')} 0 .. $#keys_to_sort;
if ($data_type eq 'number') {
@sorted_indexes = sort {($keys_to_sort[$b] // 0) <=> ($keys_to_sort[$a] // 0)} 0 .. $#keys_to_sort;
}
else {
@sorted_indexes = sort {($keys_to_sort[$a] // '') cmp ($keys_to_sort[$b] // '')} 0 .. $#keys_to_sort;
}
}
return [ @{$data}[ @sorted_indexes ] ];
}
Expand Down
6 changes: 3 additions & 3 deletions t/dummy_home/show_dummy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wg0 eOSNqjwOrtIQMOaVxOXXdGjvgQ6gIzS09ltKJMjAPl8= MN6ipoevVEFdsQ+vciTdsgeD30e9w0qT2jPZOFotmHQ= 51861 off
wg0 2mO59ijYCvfJUi6pnNO0H697xiZHTzs4mLA5da5m13w= (none) 89.333.25.1:5589 10.0.10.50/32 0 1234 5985 off
wg0 KpXASgjXPh5xtIxFclQUZzq4PuqbDfHT1CaU8shTsVE= (none) 8.8.8.8:42 10.0.10.51/32 0 4242 4242 off
wg0 Mu46ORALOMuD/T/uyuBiJNecOps4q80TB6BH6F2W9SA= (none) 45.68.254.22:6633 10.0.10.52/32 0 5 10 off
wg0 2mO59ijYCvfJUi6pnNO0H697xiZHTzs4mLA5da5m13w= (none) 89.333.25.1:5589 10.0.10.50/32 52 1234 5985 off
wg0 KpXASgjXPh5xtIxFclQUZzq4PuqbDfHT1CaU8shTsVE= (none) 8.8.8.8:42 10.0.10.51/32 4589 4528289367867 4242 off
wg0 Mu46ORALOMuD/T/uyuBiJNecOps4q80TB6BH6F2W9SA= (none) 45.68.254.22:6633 10.0.10.52/32 4567898 5 10 off

0 comments on commit d0b5776

Please sign in to comment.