openvpn remote authentication via bash script

Scripts which allow the use of special authentication methods (LDAP, AD, MySQL/PostgreSQL, etc).

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
eric66300
OpenVPN Power User
Posts: 57
Joined: Fri Apr 15, 2011 12:05 pm

openvpn remote authentication via bash script

Post by eric66300 » Tue Sep 13, 2011 7:52 am

hi

im using cent OS 5.6 and im a confused how it's to be done exactly the way i want it to be.

can somebody help me?



i put this on server side
auth-user-pass-verify "/etc/openvpn/auth_vpn.sh" via-file
and put this code inside auth_vpn.sh
#!/bin/bash
### Database Informations
DBUSER='user'
DBPASS='pass'
DBHOST='x.x.x.x'
DBNAME='dbase'

user_name=`head -n1 $1 | tail -1` #first line -> Username
pass_word=`head -n2 $1 | tail -1 ` #second line -> Password

user_query=`mysql -u $DBUSER -p$DBPASS -D $DBNAME -h $DBHOST --skip-column-name -e "SELECT username FROM user WHERE ( (active = '1') AND (username = '$user_name') AND (password = ('$pass_word')) );" $DBNAME`

if [ "$user_query" == "$user_name" ]; then
exit 0
else
exit 1
fi
pls help me

thank you

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: openvpn remote authentication via bash script

Post by janjust » Tue Sep 13, 2011 7:58 am

did you debug the script?
what happens if you print out the username+password after reading them from file - are they correct?
what happens if you manually execute the mysql query with the username+password?

this is a forum about openvpn , not about mysql/shell script debugging...

eric66300
OpenVPN Power User
Posts: 57
Joined: Fri Apr 15, 2011 12:05 pm

Re: openvpn remote authentication via bash script

Post by eric66300 » Wed Sep 14, 2011 8:19 am

Hi

sorry for my ignorance how may i print out the result after reading it from file?

tying to execute mysql both username and password are correct.

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: openvpn remote authentication via bash script

Post by janjust » Wed Sep 14, 2011 8:48 am

add these lines

Code: Select all

user_name=`head -n1 $1 | tail -1` #first line -> Username
pass_word=`head -n2 $1 | tail -1 ` #second line -> Password

# add these lines
echo "user_name=[$user_name]"
echo "pass_word=[$pass_word]"
and check to see that the right values are there. Adding things like

Code: Select all

set -vx
to the script will also produce lots of debugging output

eric66300
OpenVPN Power User
Posts: 57
Joined: Fri Apr 15, 2011 12:05 pm

Re: openvpn remote authentication via bash script

Post by eric66300 » Wed Sep 14, 2011 12:07 pm

thanks i got to try it tomorrow

too busy today.

thank you again

eric66300
OpenVPN Power User
Posts: 57
Joined: Fri Apr 15, 2011 12:05 pm

Re: openvpn remote authentication via bash script

Post by eric66300 » Thu Sep 15, 2011 7:08 am

./auth_vpn.sh: line 11: unexpected EOF while looking for matching
./auth_vpn.sh: line 18: synteax error: enexpected end of file
head: cannot open 'database' for reading: No such file or directory
head: cannot open 'database' for reading: No such file or directory

but what weird later i got authenticated using this script dont know what i did just it happen then tried to insert another data to the database and BOOM!! can't authenticate again.


ooppsss i put this code and it works for i little time
auth-user-pass-verify "/etc/openvpn/auth_vpn.sh" via-env
i change via-file into via-env

did i miss something?

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: openvpn remote authentication via bash script

Post by janjust » Thu Sep 15, 2011 7:16 am

i change via-file into via-env
that means the username+password will be available via env vars, but you must add

Code: Select all

script-security 3
to the openvpn server config if you have not already done so.

If you want to try it using 'via-file' then create a sample password file /tmp/password containing only:

Code: Select all

testuser
testpasword
then run

Code: Select all

bash -vx /etc/openvpn/auth_vpn.sh /tmp/password
and look for any errors.

eric66300
OpenVPN Power User
Posts: 57
Joined: Fri Apr 15, 2011 12:05 pm

Re: openvpn remote authentication via bash script

Post by eric66300 » Thu Sep 15, 2011 8:09 am

got error
/etc/openvpn/auth_vpn.sh: line 11: unexpected EOF while looking for matching
/etc/openvpn/auth_vpn.sh: line 20: syntax error: unexpected EOF while looking for matching

wew kinda got headache

eric66300
OpenVPN Power User
Posts: 57
Joined: Fri Apr 15, 2011 12:05 pm

Re: openvpn remote authentication via bash script

Post by eric66300 » Thu Sep 15, 2011 8:36 am

do you have alternative way to authenticate user via mysql?

i built database and open port for this remote connection

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: openvpn remote authentication via bash script

Post by janjust » Thu Sep 15, 2011 12:38 pm

this is a scripting error, not an openvpn error; if you don't know how to write a script to talk to a mysql database then you might be better of asking your questions on a scripting/mysql forum.

eric66300
OpenVPN Power User
Posts: 57
Joined: Fri Apr 15, 2011 12:05 pm

Re: openvpn remote authentication via bash script

Post by eric66300 » Sat Oct 01, 2011 6:27 am

Hi


Wanna say thank you to you without you i can't figure out what's wrong on our sql query

:D your the best sir

now our code is perfectly working now :D

padhu
OpenVpn Newbie
Posts: 4
Joined: Mon Mar 05, 2012 11:44 am

Re: openvpn remote authentication via bash script

Post by padhu » Tue Mar 06, 2012 4:24 pm

eric66300 wrote:Hi


Wanna say thank you to you without you i can't figure out what's wrong on our sql query

:D your the best sir

now our code is perfectly working now :D
Can you please share your solution here.I am having same problem.

esson
OpenVpn Newbie
Posts: 3
Joined: Tue Mar 13, 2012 2:04 am

Re: openvpn remote authentication via bash script

Post by esson » Sat Mar 17, 2012 4:02 am

Please share~ :roll:
http://beatwap.com

Post Reply