5 changed files with 48 additions and 15 deletions
@ -1,25 +1,36 @@ |
|||||||
#!/bin/bash |
#!/bin/bash |
||||||
. /etc/openvpn/scripts/config.sh |
source config.sh |
||||||
. /etc/openvpn/scripts/functions.sh |
source functions.sh |
||||||
|
|
||||||
username=$(echap "$username") |
username=$(echap "$username") |
||||||
password=$(echap "$password") |
password=$(echap "$password") |
||||||
|
|
||||||
# Authentication |
if [ "$USELDAP" == 0 ]; then |
||||||
user_pass=$(mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -sN -e "SELECT user_pass FROM user WHERE user_id = '$username' AND user_enable=1 AND (TO_DAYS(now()) >= TO_DAYS(user_start_date) OR user_start_date IS NULL) AND (TO_DAYS(now()) <= TO_DAYS(user_end_date) OR user_end_date IS NULL)") |
# Authentication |
||||||
|
user_pass=$(mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -sN -e "SELECT user_pass FROM user WHERE user_id = '$username' AND user_enable=1 AND (TO_DAYS(now()) >= TO_DAYS(user_start_date) OR user_start_date IS NULL) AND (TO_DAYS(now()) <= TO_DAYS(user_end_date) OR user_end_date IS NULL)") |
||||||
|
|
||||||
# Check the user |
# Check the user |
||||||
if [ "$user_pass" == '' ]; then |
if [ "$user_pass" == '' ]; then |
||||||
echo "$username: bad account." |
echo "$username: bad account." |
||||||
exit 1 |
exit 1 |
||||||
fi |
fi |
||||||
|
|
||||||
result=$(php -r "if(password_verify('$password', '$user_pass') == true) { echo 'ok'; } else { echo 'ko'; }") |
result=$(php -r "if(password_verify('$password', '$user_pass') == true) { echo 'ok'; } else { echo 'ko'; }") |
||||||
|
|
||||||
if [ "$result" == "ok" ]; then |
if [ "$result" == "ok" ]; then |
||||||
echo "$username: authentication ok." |
echo "$username: authentication ok." |
||||||
exit 0 |
exit 0 |
||||||
else |
else |
||||||
echo "$username: authentication failed." |
echo "$username: authentication failed." |
||||||
exit 1 |
exit 1 |
||||||
|
fi |
||||||
|
else |
||||||
|
result=$( ldapsearch -x -h "$SERVER" -D "uid=$username,$CONNECTIONSTR" -w $pasword -b "$CONNECTIONSTR" ) |
||||||
|
if [[ $result == *"result: 0 Success"* ]]; then |
||||||
|
#echo "Logged In!" |
||||||
|
exit 0 |
||||||
|
else |
||||||
|
#echo "Invalid Creds!" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
fi |
fi |
||||||
|
Loading…
Reference in new issue