Page 1 of 1
Semi automated shell program to manage OpenVPN
Posted: Fri Nov 24, 2017 11:04 pm
by antuelle78
Hi Everyone,
This is my first post, admins please bear with me.
So back to the subject; I just finished writing and testing a bash shell script that can make OpenVPN management really simple.
It can generate any number of clients and deploy single or multiple clients to a single or several server instances.
A search feature to help locate clients in large deployments
Deploy server instances
Connect to management interface of any server instance.
I would like to share this code with the community.
Anyone interested in helping improve the code is welcome.
If this interest anybody, lets have some fun
Re: Semi automated shell program to manage OpenVPN
Posted: Fri Nov 24, 2017 11:22 pm
by antuelle78
Can someone tell me how I can upload the code?
The script has 744 line plus it needs the entire easy-rsa directory and some add elements to work
Its pretty simple code and is well commented. I am not a shell programmer!
Can a moderator help us?
Re: Semi automated shell program to manage OpenVPN
Posted: Fri Nov 24, 2017 11:36 pm
by antuelle78
Ok no responses hmm.. boring topic I think, maybe I am the only lazy person here.
I am gonna try to paste the search function to give an example
getinfo () {
clear
echo -n "Enter CN of client: "
read SRCHARG junk
echo `cat $SRVDEPD`
echo -n "Choose server IP from list of deployed instances or provide new host IP: "
read SRV2SRCH junk
echo -n "Enter management interface listening port: "
read SRV2SRCHPRT junk
ssh root@$SRV2SRCH "{ echo "status 3"; sleep 1; } | telnet 127.0.0.1 $SRV2SRCHPRT" | grep "$SRCHARG" > $SRCHRLT
}
Re: Semi automated shell program to manage OpenVPN
Posted: Fri Nov 24, 2017 11:52 pm
by antuelle78
OH that looks good, lets try the entire search function, maybe that will spark some interest:
#Search FUNCTION
srchclient () {
SRCHRLT=search_result
SRVDEPD=depsrv.dat
#FUNCTION to gather info and executer manual search
getinfo () {
clear
echo -n "Enter CN of client: "
read SRCHARG junk
echo `cat $SRVDEPD`
echo -n "Choose server IP from list of deployed instances or provide new host IP: "
read SRV2SRCH junk
echo -n "Enter management interface listening port: "
read SRV2SRCHPRT junk
ssh root@$SRV2SRCH "{ echo "status 3"; sleep 1; } | telnet 127.0.0.1 $SRV2SRCHPRT" | grep "$SRCHARG" > $SRCHRLT
}
#FUNCTION for recursive/multiple server querry for a client/clients
srvlst () {
clear
echo -n "Enter CN of client you are looking for: "
read SRCHARG
while read -r SRV2SRCH SRV2SRCHPRT
do
ssh root@$SRV2SRCH "{ echo "status 3"; sleep 1; } | telnet 127.0.0.1 $SRV2SRCHPRT" | grep "$SRCHARG" > $SRCHRLT
done < depsrv.dat
}
#SEARCH menu
echo " SEARCH MENU "
echo
echo " What do you wish to do? "
echo
echo " 1. Enter info manually "
echo " 2. Search from list of available servers"
echo
echo
#
# Prompt for an answer
#
echo -n "Answer (or 'q' to quit)? "
read ans junk
#Case statement to handle options
case "$ans" in
1)
getinfo
;;
2)
srvlst
;;
esac
#Display search results and remove results data:(, we don't store anything!!!
if [ $? != 0 ] ; then
clear
echo " ##NO RESULTS FOUND##"
else
clear
echo " ###SEARCH RESULTS###"
echo
echo
more $SRCHRLT
fi
rm $SRCHRLT
echo
echo
echo " HIT <<ENTER>> to continue"
read junk
#Check if user wants to do another search
clear
if yesno Do you want to try another server/client?
then
clear
srchclient
else
menu
fi
}