Browse Source

Support invoking wgnames directly

master
vrein 10 months ago
parent
commit
03c7fed205
1 changed files with 53 additions and 11 deletions
  1. +53
    -11
      wgnames.awk

+ 53
- 11
wgnames.awk View File

@ -1,7 +1,35 @@
#!/usr/bin/awk -f
BEGIN {
color = 1;
if (debug)
printf "Num of arguments %d\n", ARGC-1;
if (ARGC > 1) {
color = 0;
for (i = 1; i < ARGC; i++) {
fulline = fulline " " ARGV[i];
if (debug)
printf "Arg no: %d --> %s\n", i, ARGV[i];
}
}
if (debug)
print "ARGS: wg" fulline;
wg = "/usr/bin/wg " fulline;
ln = 0;
while (( wg | getline line) > 0) {
wg_output[ln] = line;
ln++;
}
close(wg)
file="/etc/wireguard/wg0server.conf"
indeep = 0
if (debug)
print "############ wireguard config file parsing start"
while(( getline < file) > 0 ) {
if (debug)
print $0
@ -46,17 +74,31 @@ BEGIN {
description = ""
}
}
}
if (debug)
print "############ wireguard config file parsing end"
i = 0;
while (i < ln) {
$0 = wg_output[i]
if ($0 ~ /peer:/) {
description = description_pubkey_hash[$2]
if (description != "")
print "\033[38;5;198mdesc:"description"\033[0m";
print "\033[1;32mpeer\033[0m:", "\033[38;5;28m"$2"\033[0m";
$0 = wg_output[++i];
} else if ($0 ~ /\[Peer\]/) {
print;
$0 = wg_output[++i];
description = description_pubkey_hash[$3]
if (description != "")
print "#Description = " description
}
if (color) {
gsub("(endpoint|allowed ips|latest handshake|transfer)", "\033[1m&\033[0m"); # Make bold
gsub("(KiB|MiB|GiB|seconds?|minutes?|hours?|/)", "\033[38;5;45m&\033[0m"); # Make blue
}
print;
i++
{
if ($0 ~ /peer:/) {
description = description_pubkey_hash[$2]
if (description != "")
print "\033[38;5;198mDesc:"description"\033[0m";
print "\033[1;32mpeer\033[0m:", "\033[38;5;28m"$2"\033[0m";
getline;
}
gsub("(endpoint|allowed ips|latest handshake|transfer)", "\033[1m&\033[0m"); # Make bold
gsub("(KiB|MiB|GiB|seconds?|minutes?|hours?|/)", "\033[38;5;45m&\033[0m"); # Make blue
print;
}

Loading…
Cancel
Save