acl VPNUsers src 192.168.20.0/24 tcp_outgoing_address (VPN IP) VPNUsers
tcp_outgoing_address {VPN IP}
#!/bin/sh# VariablesVPN_IFACE=ovpnc1SQUID_CONFIG_FILE=/usr/local/etc/squid/squid.conf# Get current IP address of VPN interfaceVPN_IFACE_IP=$(ifconfig $VPN_IFACE | awk '{print $2}' | egrep -o '([0-9]+\.){3}[0-9]+')# Check if VPN interface is up and exit if it isn'tif [ -z "$VPN_IFACE_IP" ]then exit 0;fi# Check current IP for VPN interface in squid.conf fileVPN_CONFIG_IP=$(grep -m 1 "tcp_outgoing_address" $SQUID_CONFIG_FILE | awk '{print $2}' | egrep -o '([0-9]+\.){3}[0-9]+')# Check if the config file matches the current VPN interface IP, and if so exit scriptif [ "$VPN_IFACE_IP" == "$VPN_CONFIG_IP" ]then exit 0;fi# Replace the previous IP address in the squid.conf file with the current VPN interface addresssed -ie 's/'"$VPN_CONFIG_IP"'/'"$VPN_IFACE_IP"'/' $SQUID_CONFIG_FILE# Force reload of the new squid.conf file/usr/local/sbin/squid -k reconfigure
# VariablesVPN_IFACE=ovpnc1SQUID_CONFIG_FILE=/usr/local/etc/squid/squid.conf# Get current IP address of VPN interfaceVPN_IFACE_IP=$(ifconfig $VPN_IFACE | awk '{print $2}' | egrep -o '([0-9]+\.){3}[0-9]+')# Check if VPN interface is up and exit if it isn'tif [ -z "$VPN_IFACE_IP" ]then exit 0;fi# Check current IP for VPN interface in squid.conf fileVPN_CONFIG_IP=$(grep -m 1 "tcp_outgoing_address" $SQUID_CONFIG_FILE | awk '{print $2}' | egrep -o '([0-9]+\># Check if the config file matches the current VPN interface IP, and if so exit scriptif [ "$VPN_IFACE_IP" == "$VPN_CONFIG_IP" ]then exit 0;fi# Replace the previous IP address in the squid.conf file with the current VPN interface addresssed -ie 's/'"$VPN_CONFIG_IP"'/'"$VPN_IFACE_IP"'/' $SQUID_CONFIG_FILE# Force reload of the new squid.conf file/usr/local/sbin/squid -k reconfigure
run the script by putting it in a txt file and changing the permissions to allow it to be executable. then run it by ./scriptname.sh or whatever its called.
[squidvpnproxy]command: /root/vpnscript.shparameters:type:scriptmessage: reload proxy with vpn interfacedescription: VPN via Proxy script
service configd restart