Skip to content

Commit

Permalink
fixed some validation errors, compatibility with wg-meta 0.3.x,version++
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtoobii committed Jul 18, 2021
1 parent f3d3f07 commit 34172a9
Show file tree
Hide file tree
Showing 16 changed files with 382 additions and 489 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
wg-wrangler (0.2.0) unstable; urgency=medium

* fixed: Validation on hidden field when adding a new peer
* fixed: Disabled Peer warning when editing a peer
* changed: lifted wg-meta compatibility to 0.3.x. This version may be incompatible to older (wg-meta) metadata! See changes of wg-meta

-- Tobias Bossert <[email protected]> Sun, 18 Jul 2021 13:48:02 +0200

wg-wrangler (0.1.4) unstable; urgency=medium

* wg-wrangler: removed .pl extension from main "binary" (to make it compatible for apparmor profiles)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WGwrangler
===========
Version: 0.1.0
Date: 2021-04-16
Version: 0.2.0
Date: 2021-07-18

WGwrangler is a web application to manage local Wireguard Configuration using
[wg-meta](https://metacpan.org/release/Wireguard-WGmeta) in its backend.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.4
0.2.0
4 changes: 2 additions & 2 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
requires 'CallBackery', '>= 0.37.0';
requires 'CallBackery', '>= 0.38.0';
requires 'Mojo::SQLite';
requires 'Wireguard::WGmeta', '>= 0.2.3';
requires 'Wireguard::WGmeta', '>= 0.3.0';
requires 'Net::IP', '>=1.26';
requires 'Email::MIME';
requires 'Email::Sender';
Expand Down
8 changes: 8 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
wg-wrangler (0.2.0) unstable; urgency=medium

* fixed: Validation on hidden field when adding a new peer
* fixed: Disabled Peer warning when editing a peer
* changed: lifted wg-meta compatibility to 0.3.x. This version may be incompatible to older (wg-meta) metadata! See changes of wg-meta

-- Tobias Bossert <[email protected]> Sun, 18 Jul 2021 13:48:02 +0200

wg-wrangler (0.1.4) unstable; urgency=medium

* wg-wrangler: removed .pl extension from main "binary" (to make it compatible for apparmor profiles)
Expand Down
58 changes: 30 additions & 28 deletions lib/WGwrangler/GuiPlugin/WireguardAddPeerForm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ has formCfg => sub ($self) {
},
set => {
required => true,
value => $self->config->{'default-allowed-ips'}
},
},
# peer Address override
Expand Down Expand Up @@ -199,7 +198,7 @@ has formCfg => sub ($self) {
key => 'show_advanced',
label => trm('Advanced Options'),
widget => 'checkBox',
triggerFormReset => true,
triggerFormReset => true
},
# Header
{
Expand Down Expand Up @@ -237,23 +236,23 @@ has formCfg => sub ($self) {
visibility => $show_advanced ? 'visible' : 'excluded'
},
},
# # alias (advanced)
# {
# key => 'alias',
# label => trm('Alias'),
# widget => 'text',
# triggerFormReset => true,
# validator => sub($value, $parameter, $formData) {
# if ($formData->{alias} && $formData->{interface} && $formData->{'public-key'}) {
# return $self->app->wireguardModel->validator('alias', $value, $formData->{interface}, $formData->{'public-key'});
# }
# return "" eq $value ? "" : "Please select an interface first";
# },
# set => {
# placeholder => 'Unlike the name attribute, this must be unique',
# visibility => $show_advanced ? 'visible' : 'excluded'
# }
# },
# alias (advanced)
{
key => 'alias',
label => trm('Alias'),
widget => 'text',
triggerFormReset => true,
validator => sub($value, $parameter, $formData) {
if ($formData->{alias} && $formData->{interface} && $formData->{'public-key'}) {
return $self->app->wireguardModel->validator('alias', $value, $formData->{interface}, $formData->{'public-key'});
}
return "" eq $value ? "" : "Please select an interface first";
},
set => {
placeholder => 'This attribute is useful for CLI access. Unlike the name attribute, this must be unique',
visibility => $show_advanced ? 'visible' : 'excluded'
}
},
# persistent-keepalive (advanced)
{
key => 'persistent-keepalive',
Expand Down Expand Up @@ -307,9 +306,10 @@ has actionCfg => sub ($self) {
my $peer_committed = undef;

eval {
$self->app->wireguardModel->add_peer($interface, $name, $ips, $peer_pub_key, $alias, undef);
$self->app->wireguardModel->add_peer($interface, $ips, $peer_pub_key, $alias, undef);
$peer_added = 1;
$self->app->wireguardModel->update_peer_data($interface, $peer_pub_key, 'description', $desc) if defined($desc);
$self->app->wireguardModel->update_peer_data($interface, $peer_pub_key, 'name', $name);
$self->app->wireguardModel->update_peer_data($interface, $peer_pub_key, 'email', $email);
$self->app->wireguardModel->update_peer_data($interface, $peer_pub_key, 'device', $device);
$self->app->wireguardModel->update_peer_data($interface, $peer_pub_key, 'created', $created);
Expand Down Expand Up @@ -380,10 +380,10 @@ sub generate_preview_config ($form_values, $client_private_key, $interface_publi
# }
my $pfx = '#+';
my $out = "[Interface]\n"
. $pfx . "Name = " . ($form_values->{name} ? $form_values->{name} . "\n" : "\n")
. $pfx . "Email = " . ($form_values->{email} ? $form_values->{email} . "\n" : "\n")
. $pfx . "Device = " . ($form_values->{device} ? $form_values->{device} . "\n" : "\n")
. $pfx . "Created = " . ($form_values->{created} ? $form_values->{created} . "\n" : "\n")
. $pfx . "name = " . ($form_values->{name} ? $form_values->{name} . "\n" : "\n")
. $pfx . "email = " . ($form_values->{email} ? $form_values->{email} . "\n" : "\n")
. $pfx . "device = " . ($form_values->{device} ? $form_values->{device} . "\n" : "\n")
. $pfx . "created = " . ($form_values->{created} ? $form_values->{created} . "\n" : "\n")
. "Address = " . $form_values->{address} . "\n"
. "PrivateKey = $client_private_key\n"
. ($form_values->{DNS} ? "DNS = " . $form_values->{DNS} . "\n" : '')
Expand Down Expand Up @@ -420,23 +420,25 @@ sub getAllFieldValues ($self, $args, $formData, $qx_locale) {
}
# generate key-pair unless we already have one
my $private_key = "";
my $public_key = "";
unless ($formData->{currentFormData}{'private-key'}) {
my $key_pair = $self->app->wireguardModel->gen_key_pair();
$private_key = $key_pair->{'private-key'};
$data->{'private-key'} = $key_pair->{'private-key'};
$data->{'public-key'} = $key_pair->{'public-key'};
$public_key = $key_pair->{'public-key'};
}
else {
$private_key = $formData->{currentFormData}{'private-key'};
$public_key = $formData->{currentFormData}{'public-key'};
}

$data->{'private-key'} = $private_key;
$data->{'public-key'} = $public_key;
$data->{'config_preview'} = generate_preview_config($formData->{currentFormData}, $private_key, $interface_public_key);
}
else {
$data->{'config_preview'} = 'Select an interface first';
}

$data->{'created'} = strftime("%Y-%m-%d %H:%M:%S %z", localtime);
$data->{'allowed-ips'} = $self->config->{'default-allowed-ips'};
$data->{'DNS'} = $self->config->{'default-dns'};

return $data;
Expand Down
6 changes: 2 additions & 4 deletions lib/WGwrangler/GuiPlugin/WireguardEditPeerForm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ Peer edit form
=cut

has formCfg => sub ($self) {

return [
# This does somehow not work $self->{args}{selection}{disabled} is a reference to JSON::PP true
1 ? {
$self->{args}{selection}{disabled} == true ? {
widget => 'header',
label => trm('<color="red">Warning</color>'),
note => trm('This Peer is disabled!'),
Expand Down Expand Up @@ -129,7 +127,7 @@ has actionCfg => sub ($self) {
my $before_change = $self->app->wireguardModel->get_section_data($interface, $identifier);
eval {
for my $attr_key (keys %{$args}) {
unless ($attr_key eq 'interface' || $attr_key eq 'public-key' || $attr_key eq 'integrity_hash') {
unless ($attr_key eq 'interface' || $attr_key eq 'public-key' || $attr_key eq 'integrity_hash' || not defined($args->{$attr_key})) {
$self->app->wireguardModel->update_peer_data($interface, $identifier, $attr_key, $args->{$attr_key});

}
Expand Down
1 change: 0 additions & 1 deletion lib/WGwrangler/GuiPlugin/WireguardShow.pm
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ sub getTableData ($self, $args, $qx_locale) {
toggle => {
enabled => true,
label => ($row->{'disabled'}) ? trm('Enable Peer') : trm('Disable Peer')

}
}
}
Expand Down
18 changes: 9 additions & 9 deletions lib/WGwrangler/Model/WireguardDataAdapter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ has 'wg_not_installed' => sub {
has 'wg_meta' => sub ($self) {
my $custom_attr_config = {
'email' => {
'in_config_name' => 'Email',
'validator' => sub ($value) {return $value =~ /^\S+@\S+\.\S+$/;}
'validator' => sub($value) {return $value =~ /^\S+@\S+\.\S+$/;}
},
device => {
'in_config_name' => 'Device',
'validator' => sub ($value) {return 1}
'validator' => sub($value) {return 1}

},
created => {
'in_config_name' => 'Created',
'validator' => sub ($value) {return 1}
'validator' => sub($value) {return 1}
},
fqdn => {
'validator' => sub($value) {return 1}
}
};
my $wg_metaT = Wireguard::WGmeta::Wrapper::ConfigT->new($self->wireguard_home, '#+', '#-', $self->not_applied_suffix, $custom_attr_config);
Expand Down Expand Up @@ -195,7 +195,7 @@ Returns the number of peers with respect to the current filter string
=cut
sub get_peer_count ($self, $filter) {
my $filtered_data = _apply_filter($self->_generate_table_source(), $filter);
return @{$filtered_data};
return scalar @{$filtered_data};
}

=head3 update_peer_data($interface, $identifier, $attr, $value)
Expand All @@ -216,8 +216,8 @@ L</commit_changes($ref_integrity_hashes)> manually to allow setting additional a
to disk.
=cut
sub add_peer ($self, $interface, $name, $ip_address, $public_key, $alias, $pre_shared_key) {
$self->wg_meta->add_peer($interface, $name, $ip_address, $public_key, $alias, $pre_shared_key);
sub add_peer ($self, $interface, $ip_address, $public_key, $alias, $pre_shared_key) {
$self->wg_meta->add_peer($interface, $ip_address, $public_key, $alias, $pre_shared_key);
}

=head3 remove_peer($interface, $identifier, $ref_integrity_hash)
Expand Down
Loading

0 comments on commit 34172a9

Please sign in to comment.