diff --git a/configs/pip/pip.conf b/configs/pip/pip.conf new file mode 100644 index 0000000..b4eab0e --- /dev/null +++ b/configs/pip/pip.conf @@ -0,0 +1,3 @@ +[global] +break-system-packages = true +user = true \ No newline at end of file diff --git a/install-linux.sh b/install-linux.sh index 7c27ac3..1a85341 100644 --- a/install-linux.sh +++ b/install-linux.sh @@ -35,6 +35,7 @@ mkdir -p ~/.config/systemd/user mkdir -p ~/.config/glab-cli mkdir -p ~/.config/user-tmpfiles.d mkdir -p ~/.config/gqrx +mkdir -p ~/.config/pip mkdir -p ~/.cargo mkdir -p ~/.ssh @@ -95,6 +96,9 @@ ln -sf $EWCONFIG_ROOT/configs/user-tmpfiles.d/* ~/.config/user-tmpfiles.d/ # Logid config ln -sf $EWCONFIG_ROOT/configs/logid/logid.cfg ~/.config/logid/logid.cfg +# Pip config +ln -sf $EWCONFIG_ROOT/configs/pip/pip.conf ~/.config/pip/pip.conf + # GQRX ln -sf $EWCONFIG_ROOT/configs/gqrx/bookmarks.csv ~/.config/gqrx/bookmarks.csv diff --git a/scripts/vpn-last-handshakes b/scripts/vpn-last-handshakes new file mode 100755 index 0000000..c4663cb --- /dev/null +++ b/scripts/vpn-last-handshakes @@ -0,0 +1,63 @@ +#! /usr/bin/env python3 +import argparse +import sys +import logging +import requests +import subprocess +from datetime import datetime + +logger = logging.getLogger(__name__) + + +def main() -> int: + # Handle program arguments + ap = argparse.ArgumentParser(prog="", description="") + + ap.add_argument( + "-v", "--verbose", help="Enable verbose logging", action="store_true" + ) + args = ap.parse_args() + + # Configure logging + logging.basicConfig( + level=logging.DEBUG if args.verbose else logging.INFO, + format="%(levelname)s: %(message)s", + ) + + # Make request + response = requests.get( + "http://gateway.vpn:9090/api/v1/query?query=wireguard_latest_handshake_seconds" + ) + + # Parse into a list of peers + peers = response.json()["data"]["result"] + logger.debug(f"Found {len(peers)} peers") + + # Handle each peer + now = datetime.now() + for peer in peers: + allowed_ips = peer["metric"]["allowed_ips"] + latest_handshake = peer["value"][1] + + # Figure out the friendly name + first_ip = allowed_ips.split(",")[0].split("/")[0] + name = ( + subprocess.check_output( + ["dig", "+short", "-x",first_ip ] + ) + .decode("utf-8") + .strip() + ) + + # Construct the output + output = f"{first_ip}" + if name: + output += f" ({name})" + output += f" {(now - datetime.fromtimestamp(int(latest_handshake))).seconds}" + print(output) + + return 0 + + +if __name__ == "__main__": + sys.exit(main())