first commit
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user