0

I want to check that the ip is present within the ccd folder and push the ip route to the FORWARDING chain in the iptables. Im new to bash scripting and need a little help finishing this script.

client file in /etc/openvpn/ccd :

ifconfig-push 10.8.0.45 255.255.255.0
push 'route 10.10.0.45'

I need to grep 10.8.0.45 & 10.10.0.45

and push those routes in the iptables. e.g

iptables -A FORWARD -s 10.8.0.45 -d 10.10.0.45 -j ACCEPT

client-connect /etc/openvpn/on_connect.sh

script I need help with 'grep' or 'awk'

static_ip=  grep "^push \"route" | grep "^'" | cut -f2 -d" "

ip_destination=grep "^push \"route" | grep "^'" | cut -f3 -d" "
#!/usr/bin/env bash
#
#  Add iptables rules based on CCD client config.
#

CCD_DIR="/etc/openvpn/ccd"
# iptables rule comment - the disconnect script will
# remove all strings matching this pattern
RULE_COMMENT="OVPN_"$common_name
static_ip=grep..
ip_destination=grep..



if [ -f $CCD_DIR/$common_name ]; then
  sudo iptables -A FORWARD -s $static_ip -d ip_destination -j ACCEPT
fi

exit 0
Kam-ALIEN
  • 19
  • 5

1 Answers1

1

If you want to grep for files in the openvpn directory, grep -R /etc/openvpn/ccd -E '10.(8|45).0.45' To see if this returns success, you can do:

 if grep -qRE /etc/openvpn/ccd '10\.(8|45)\.0\.45' ; then
    : # do somethig
 fi

HTH.

P.S. I wanted to add comments to ask for more details, but I dont have enough points to comment

Ani
  • 32
  • 2
  • 13