Wireguard-WGmeta

 view release on metacpan or  search on metacpan

lib/Wireguard/WGmeta/Parser/Show.pm  view on Meta::CPAN

    {
        'interface_name' => {
            'a_peer_pub_key' => {
                'interface'     => <parent_interface>,
                'public-key'    => <interface_public_key>,
                'preshared-key' => <interface_preshared_key>,
                'and_so_on'     => <value_of_attr>
            },
            'an_interface_name => {
                'interface'     => <parent_interface>,
                'private-key'   => <interface_private_key>,
                'and_so_on'     => <value_of_attr>
            }
        },
        'an_other_interface' => {
            [...]
        }
    }

An important remark: This parser is relatively intolerant when it comes to formatting due to the input is already in a "machine readable" format.
It expects one peer/interface per line, the values in the exact same order as defined in @keys_peer/@keys_interface,

lib/Wireguard/WGmeta/Wrapper/Bridge.pm  view on Meta::CPAN


=cut
sub gen_keypair() {
    unless (defined $ENV{WGmeta_NO_WG}){
        my (@out_priv, undef) = run_external('wg genkey');
        my (@out_pub, undef) = run_external('wg pubkey', $out_priv[0]);
        chomp @out_priv;
        chomp @out_pub;
        return $out_priv[0], $out_pub[0];
    }
    return 'dummy_private_key', 'dummy_public_key';
}
=head2 get_pub_key($priv_key)

Runs C<wg pubkey> on C<$priv_key>.

B<Parameters>

=over 1

=item

lib/Wireguard/WGmeta/Wrapper/Config.pm  view on Meta::CPAN

}

sub get_wg_meta_prefix($self) {
    return $self->{wg_meta_prefix};
}

sub get_disabled_prefix($self) {
    return $self->{wg_meta_disabled_prefix};
}

=head3 add_interface($interface_name, $ip_address, $listen_port, $private_key)

Adds a (minimally configured) interface. If more attributes are needed, please set them using the C<set()> method.

B<Caveat:> No validation is performed on the values!

B<Parameters>

=over 1

=item *

lib/Wireguard/WGmeta/Wrapper/Config.pm  view on Meta::CPAN

=item *

C<$ip_address> A string describing the ip net(s) (e.g '10.0.0.0/24, fdc9:281f:04d7:9ee9::2/64')

=item *

C<$listen_port> The listen port for this interface.

=item *

C<$private_key> A private key for this interface

=back

B<Raises>

An exception if the interface name already exists.

B<Returns>

None

=cut
sub add_interface($self, $interface_name, $ip_address, $listen_port, $private_key) {
    if ($self->is_valid_interface($interface_name)) {
        die "Interface `$interface_name` already exists";
    }
    my %interface = (
        'address'                     => $ip_address,
        'listen-port'                 => $listen_port,
        'private-key'                 => $private_key,
        INTERNAL_KEY_PREFIX . 'type'  => 'Interface',
        INTERNAL_KEY_PREFIX . 'order' => [ 'address', 'listen-port', 'private-key' ]
    );
    $self->{parsed_config}{$interface_name}{$interface_name} = \%interface;
    $self->{parsed_config}{$interface_name}{INTERNAL_KEY_PREFIX . 'alias_map'} = {};
    $self->{parsed_config}{$interface_name}{INTERNAL_KEY_PREFIX . 'section_order'} = [ $interface_name ];
    $self->{parsed_config}{$interface_name}{checksum} = 'none';
    $self->{parsed_config}{$interface_name}{INTERNAL_KEY_PREFIX . 'mtime'} = 0.0;
    $self->{parsed_config}{$interface_name}{INTERNAL_KEY_PREFIX . 'config_path'} = $self->{wireguard_home} . $interface_name . '.conf';
    $self->{parsed_config}{$interface_name}{has_changed} = 1;



( run in 0.237 second using v1.01-cache-2.11-cpan-4d50c553e7e )