From beaab968a8a8c483f1d3579e9b13840e087e6646 Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 4 Mar 2023 22:37:01 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=8C=88=20Add=20more=20Colors=20and=20?= =?UTF-8?q?simplify=20color=20codes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wg-info | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/wg-info b/wg-info index ed8c90b..7e93b75 100755 --- a/wg-info +++ b/wg-info @@ -14,16 +14,24 @@ if 'html' in sys.argv: greenbldfmt = '' yellowfmt = '' yellowbldfmt = '' + cyanfmt = '' + cyanbldfmt = '' + magentafmt = '' + magentabldfmt = '' bldfmt = '' endfmt = '' elif sys.stdout.isatty() or 'tty' in sys.argv: output = 'tty' - redfmt = '\033[0;31m' - redbldfmt = '\033[1;31m' - greenfmt = '\033[0;32m' - greenbldfmt = '\033[1;32m' - yellowfmt = '\033[0;33m' - yellowbldfmt = '\033[1;33m' + redfmt = '\033[31m' + redbldfmt = '\033[31;1m' + greenfmt = '\033[32m' + greenbldfmt = '\033[32;1m' + yellowfmt = '\033[33m' + yellowbldfmt = '\033[33;1m' + cyanfmt = '\033[36m' + cyanbldfmt = '\033[36;1m' + magentafmt = '\033[35m' + magentabldfmt = '\033[35;1m' bldfmt = '\033[1m' endfmt = '\033[0m' else: @@ -34,6 +42,10 @@ else: greenbldfmt = '' yellowfmt = '' yellowbldfmt = '' + cyanfmt = '' + cyanbldfmt = '' + magentafmt = '' + magentabldfmt = '' bldfmt = '' endfmt = '' @@ -92,13 +104,28 @@ def show_info(interface): colorfmt = redfmt colorbldfmt = redbldfmt print(' ' + colorbldfmt + 'peer' + endfmt + ': ' + colorfmt + - peers[peer_pubkey]['name'] + ' ('+peer_pubkey+')' + endfmt) + peers[peer_pubkey]['name'] + endfmt + ' ('+peer_pubkey+')' ) elif line.startswith('interface:'): peer_section = False interface = line.split(':', 1)[1].strip() print(yellowbldfmt + 'interface' + endfmt + ': ' + yellowfmt + interface + endfmt) elif line.startswith('preshared key:') or line.startswith('private key:'): continue + elif line.startswith('endpoint'): + key = line.split(':')[0].strip() + value = line.split(':', 1)[1].strip() + indent = ' ' if peer_section else ' ' + print(indent + key + ': ' + cyanbldfmt + value + endfmt) + elif line.startswith('allowed ips'): + key = line.split(':')[0].strip() + value = line.split(':', 1)[1].strip() + indent = ' ' if peer_section else ' ' + print(indent + key + ': ' + greenbldfmt + value + endfmt) + elif line.startswith('latest handshake'): + key = line.split(':')[0].strip() + value = line.split(':', 1)[1].strip() + indent = ' ' if peer_section else ' ' + print(indent + key + ': ' + magentabldfmt + value + endfmt) elif line: key = line.split(':')[0].strip() value = line.split(':', 1)[1].strip() From f4a5c2d53788393a18501423e3f4990bcd4d42ab Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 31 Mar 2023 01:20:23 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20Fix=20and=20improve=20checking?= =?UTF-8?q?=20if=20peer=20is=20online?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wg-info | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wg-info b/wg-info index 7e93b75..7f78797 100755 --- a/wg-info +++ b/wg-info @@ -57,6 +57,7 @@ def read_config(interface): peer_name = "*nameless*" peer_pubkey = "" peer_ip = "" + peer_online = "" with open('/etc/wireguard/%s.conf' % interface) as cfg: for line in cfg.readlines(): @@ -97,18 +98,21 @@ def show_info(interface): peer_section = True peer_pubkey = line.split(':', 1)[1].strip() - if peers[peer_pubkey].get('online', True): + if peers[peer_pubkey].get('online') is None: + colorfmt = yellowfmt + colorbldfmt = yellowbldfmt + elif peers[peer_pubkey].get('online') is True: colorfmt = greenfmt colorbldfmt = greenbldfmt else: colorfmt = redfmt colorbldfmt = redbldfmt - print(' ' + colorbldfmt + 'peer' + endfmt + ': ' + colorfmt + + print(' ' + 'peer: ' + colorfmt + peers[peer_pubkey]['name'] + endfmt + ' ('+peer_pubkey+')' ) elif line.startswith('interface:'): peer_section = False interface = line.split(':', 1)[1].strip() - print(yellowbldfmt + 'interface' + endfmt + ': ' + yellowfmt + interface + endfmt) + print('interface: ' + yellowfmt + interface + endfmt) elif line.startswith('preshared key:') or line.startswith('private key:'): continue elif line.startswith('endpoint'):