Commit 47f8dd80 authored by Matthew Smith's avatar Matthew Smith
Browse files

Fix bugs in make-static-ip

parent 43d97337
......@@ -11,8 +11,7 @@ COMMONNAME=$1
. /etc/openvpn-server/config.sh
CCDDIR=/etc/openvpn/ccd/
#SHOREWALLVARS=/etc/shorewall/openvpn.vars
SHOREWALLVARS=/tmp/openvpn.vars
SHOREWALLVARS=/etc/shorewall/openvpn.vars
IPPREFIX=`cat /etc/openvpn/$OVPN_ORGNICK-server.conf |grep 'server '|cut -f2 -d' '|cut -f1,2,3 -d.`.
IP=`cat /etc/openvpn/$OVPN_ORGNICK-server.conf | grep '^server '| cut -f2 -d' '`
......@@ -44,13 +43,12 @@ function prompt_restart_shorewall () {
}
function get_new_ip() {
local newip=
local newip=""
local s_ip=$1
local s_subnet=$2
# TODO: Make sure calc-ip-range.sh is set correctly before building
for i in `/usr/share/openvpn-server/calc-ip-range.sh -i $s_ip -s $s_subnet | sed -n "6~4p"` ; do
if ! grep " $i " "$CCDDIR/*" ; then
newip="$i";
if [ `grep "ifconfig-push" $CCDDIR* | grep "$i" | wc -l` -eq 0 ] ; then
local newip="$i";
break;
fi
......@@ -81,22 +79,22 @@ function get_new_ip() {
# [241,242] [245,246] [249,250] [253,254]
#
newip=$(get_new_ip $IP $SUBNET);
ip=$(get_new_ip $IP $SUBNET);
if [ -x $newip ] ; then
if [ -x $ip ] ; then
echo "we appear to have run out of ip's, fix it"
echo "then run \$ $0 $COMMONNAME"
else
IFS='.' read -ra ipnums <<< $newip
IFS='.' read -ra ipnums <<< $ip
(( ipnums[3]++ ))
newgw=$(echo ${ipnums[*]} | sed "s/ /\./g")
echo "your new ip will be $newip"
echo "your new ip will be $ip"
echo "your new gateway will be $newgw"
echo "writing new ccd for you"
echo ifconfig-push $newip $newgw > $CCDDIR/$COMMONNAME
echo ifconfig-push $ip $newgw > $CCDDIR$COMMONNAME
echo "writing new shorewall vars"
grep "ifconfig-push" /etc/openvpn/ccd/* | sed "s/[\/|:]/ /g" | awk '{print $4 "=" $6}' > $SHOREWALLVARS
grep "ifconfig-push" $CCDDIR* | sed "s/[\/|:]/ /g" | awk '{print $4 "=" $6}' > $SHOREWALLVARS
prompt_restart_shorewall
fi
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment