From 257ea183c566b1e67e3d2a54c0c7efa321a5fa75 Mon Sep 17 00:00:00 2001 From: Adora Laura Kalb Date: Thu, 23 May 2024 10:01:02 +0200 Subject: [PATCH] update stuff --- mailcow/update-adminaliases.py | 7 ++-- wireguard/new-peer.sh | 60 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100755 wireguard/new-peer.sh diff --git a/mailcow/update-adminaliases.py b/mailcow/update-adminaliases.py index 60f997f..50c6cc4 100755 --- a/mailcow/update-adminaliases.py +++ b/mailcow/update-adminaliases.py @@ -1,14 +1,15 @@ #!/usr/bin/env python3 import time -start_time = time.time() - import argparse import logging import requests import json -from config import * +from config import config +start_time = time.time() + + headers = { 'X-API-Key': config['apikey'], diff --git a/wireguard/new-peer.sh b/wireguard/new-peer.sh new file mode 100755 index 0000000..a92f0a1 --- /dev/null +++ b/wireguard/new-peer.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +clientdir=/etc/wireguard/clients +endpoint="vpn.example.net:5999" + +echo "Name of new peer?" +read peername + +echo "IP of new peer? (without CIDR)" +read peerip + +if [ -f $clientdir/$peername.conf ]; then + echo "peer $peername already exists. Exiting..." + exit 1 +fi + +# generating the clients private key +client_privatekey=$(wg genkey) +echo "$client_privatekey" > $clientdir/$peername-private.key + +# generating the clients public key from the private key +client_publickey=$(echo "$client_privatekey" | wg pubkey) +echo "$client_publickey" > $clientdir/$peername-public.key + +# getting the PSK +psk=$(cat /etc/wireguard/psk.key) + +# getting server public key +server_publickey=$(cat /etc/wireguard/server_public.key) + +echo "" +echo "" +echo "########################################################" +echo "########## config for /etc/wireguard/wg0.conf ##########" + +cat << EOF +# $peername +[Peer] +PublicKey = $client_publickey +PresharedKey = $psk +AllowedIPs = $peerip/32 +EOF + +echo "" +echo "" +echo "########################################################" +echo "################## Client-Config #######################" +cat | tee $clientdir/$peername.conf << EOF +[Interface] +PrivateKey = $client_privatekey +Address = $peerip/32 +DNS = 192.168.21.2, 192.168.21.3 + +[Peer] +PublicKey = $server_publickey +PresharedKey = $psk +AllowedIPs = 0.0.0.0/0 +Endpoint = $endpoint +PersistentKeepalive = 25 +EOF