# Sample VPN traffic every 5 minutes and bill it to the owning account.
#
# WireGuard counters are cumulative per peer and reset when a peer is re-added
# or the interface restarts, so usage has to be measured as a DELTA between
# samples. This is also where a data cap is actually enforced: an account that
# crosses its allowance has its tunnels closed here, rather than only being
# refused the next time it reconnects.
#
# Runs as www-data because it writes the panel's own stores under
# /var/www/alpha-private and calls the alpha-vpn helper through sudo.
#
# Harmless everywhere: the script exits immediately when WireGuard is not
# installed, so shipping this cron to every panel costs nothing.
*/5 * * * * www-data [ -f /var/www/alpha/bin/vpn-usage.php ] && /usr/bin/php /var/www/alpha/bin/vpn-usage.php >/dev/null 2>&1
