Browse Source

Created a LDAP loging option in shell (Still basic)

feature/ldap
dries peeters 8 years ago committed by Chocobozzz
parent
commit
294486e779
  1. 8
      include/functions.php
  2. 8
      installation/scripts/config.sh
  3. 0
      installation/scripts/functions.sh
  4. 15
      installation/scripts/login.sh
  5. 6
      sql/schema-0.sql

8
include/functions.php

@ -51,12 +51,20 @@ function loginLDAP($serverFQDN, $username, $password)
//check if user exists if works return true if not return false //check if user exists if works return true if not return false
if ($bind = ldap_bind($ldap, $username, $password)) if ($bind = ldap_bind($ldap, $username, $password))
{ {
//return true when login is OK.
return true; return true;
} }
else else
{ {
//return false when login is NOK
return false; return false;
} }
} }
//get all LDAP users and place them inside a database.
function getLDAPUsers()
{
}
?> ?>

8
installation/scripts/config.sh

@ -1,5 +1,13 @@
#!/bin/bash #!/bin/bash
#use LDAP set to 1
USELDAP=1
#LDAP credentials
SERVER='ldap.forumsys.com'
#put your own DC info here
CONNECTIONSTR='dc=example,dc=com'
# MySQL credentials # MySQL credentials
HOST='localhost' HOST='localhost'
PORT='3306' PORT='3306'

0
installation/scripts/functions.sh

15
installation/scripts/login.sh

@ -1,10 +1,11 @@
#!/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")
if [ "$USELDAP" == 0 ]; then
# Authentication # 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)") 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)")
@ -23,3 +24,13 @@ else
echo "$username: authentication failed." echo "$username: authentication failed."
exit 1 exit 1
fi 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

6
sql/schema-0.sql

@ -33,3 +33,9 @@ CREATE TABLE IF NOT EXISTS `user` (
PRIMARY KEY (`user_id`), PRIMARY KEY (`user_id`),
KEY `user_pass` (`user_pass`) KEY `user_pass` (`user_pass`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE IF NOT EXISTS `uLDAP` (
`user_id` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`user_online` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Loading…
Cancel
Save