Class for parsing the output of wg show dump.
wg show dump
use Wireguard::WGmeta::Wrapper::Show; my $wg_show = Wireguard::WGmeta::Wrapper::Show->new(<wg show dump output as string>);
This class contains a parser for the output of wg show dump together with an interface to retrieve the parsed data. An important note tough: This class does not perform the necessary I/O by itself and therefore the actual output of the command wg show dump has to be captured into a string externally (e.g using "get_wg_show([$cmd])" in Wireguard::WGmeta::Wrapper::Bridge).
use Wireguard::WGmeta::Wrapper::Show; use Wireguard::WGmeta::Wrapper::Bridge; my ($out, $err) = get_wg_show(); my $wg_show = Wireguard::WGmeta::Wrapper::Show->new($out); # get a specfic interface section wg_show->get_interface_section('wg0', '<interface_public_key>') # the parser is also exported as standalone my $ref_hash_parsed_show = wg_show_dump_parser($out)
Creates a new instance of the show parser
Parameters
$wg_show_dump Output of the (external) command wg show dump.
$wg_show_dump
Returns
Instance
Parser for the output of wg show dump. Aims to create a compatible structure as "read_wg_configs($wireguard_home, $wg_meta_prefix, $disabled_prefix)" in Wireguard::WGmeta::Wrapper::Config:
{ '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, separated by a whitespace character. Usually, you don't have to worry about this - it is just meant as word of warning.
$input Output of wg show dump
$input
A reference to a hash with the structure described above.
Returns a list with all available interface names
A list with valid interface names.
Simply checks if data is available for a specific interface. Useful to check if an interface is up.
$interface An interface name
$interface
If yes, returns True else False
Returns a specific section of an interface
$interface A valid interface name, optimally retrieved through "get_interface_list()".
$identifier A valid identifier, if the requested section is a peer this is its public-key, otherwise the interface name again.
$identifier
A hash of the requested section. If non-existent, empty hash.
Returns a sorted list of all peers belonging to given interface
A list of peer public-keys (identifiers), if the interface does not exist -> empty list.
Simple dumper method to print contents of $self->{parsed_show}.
$self->{parsed_show}
To install Wireguard::WGmeta::Utils, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Wireguard::WGmeta::Utils
CPAN shell
perl -MCPAN -e shell install Wireguard::WGmeta::Utils
For more information on module installation, please visit the detailed CPAN module installation guide.