first commit

This commit is contained in:
Stefan Hacker
2026-02-02 09:46:35 +01:00
commit 6901dc369b
98 changed files with 13030 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
#!/bin/bash
# OpenVPN client-connect script
# Called when a client connects successfully
# Environment variables provided by OpenVPN:
# - common_name: Client certificate CN
# - trusted_ip / untrusted_ip: Client's real IP
# - ifconfig_pool_remote_ip: Assigned VPN IP
# - dev: TUN/TAP device
# - time_unix: Connection timestamp
# Log connection (optional - log file might not be writable)
echo "$(date '+%Y-%m-%d %H:%M:%S') CONNECT: CN=$common_name IP=$trusted_ip VPN_IP=$ifconfig_pool_remote_ip" >> /var/log/openvpn/clients.log 2>/dev/null || true
# Notify API about connection (optional)
if [ -n "$API_URL" ]; then
curl -s -X POST "$API_URL/vpn-servers/${VPN_SERVER_ID:-1}/client-connected" \
-H "Content-Type: application/json" \
-d "{\"common_name\": \"$common_name\", \"real_ip\": \"$trusted_ip\", \"vpn_ip\": \"$ifconfig_pool_remote_ip\"}" \
2>/dev/null || true
fi
exit 0
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# OpenVPN client-disconnect script
# Called when a client disconnects
# Environment variables provided by OpenVPN:
# - common_name: Client certificate CN
# - trusted_ip / untrusted_ip: Client's real IP
# - ifconfig_pool_remote_ip: Assigned VPN IP
# - bytes_received: Total bytes received from client
# - bytes_sent: Total bytes sent to client
# - time_duration: Connection duration in seconds
# Log disconnection (optional - log file might not be writable)
echo "$(date '+%Y-%m-%d %H:%M:%S') DISCONNECT: CN=$common_name Duration=${time_duration}s RX=$bytes_received TX=$bytes_sent" >> /var/log/openvpn/clients.log 2>/dev/null || true
# Notify API about disconnection (optional)
if [ -n "$API_URL" ]; then
curl -s -X POST "$API_URL/vpn-servers/${VPN_SERVER_ID:-1}/client-disconnected" \
-H "Content-Type: application/json" \
-d "{\"common_name\": \"$common_name\", \"bytes_received\": $bytes_received, \"bytes_sent\": $bytes_sent, \"duration\": $time_duration}" \
2>/dev/null || true
fi
exit 0