42 lines
1.4 KiB
Bash
42 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
export AD_DOMAIN="test"
|
|
export DOMAIN_TLD="testco.tld"
|
|
export AD_QUERY_USERNAME="ldapquery"
|
|
export AD_QUERY_PASSWORD="Ldap01-^"
|
|
export AD_DC="testdc"
|
|
|
|
#-b "cn=users,dc=test,dc=testco,dc=tld" \
|
|
# Make these into the appropriate components of above string
|
|
|
|
export DCPART1=""
|
|
export DCPART2=""
|
|
export DCPART3=""
|
|
|
|
AD_DOMAIN_FQDN="$AD_DOMAIN.$DOMAIN_TLD"
|
|
DOMAIN_CONTROLLER_FQDN="$AD_DC.$AD_DOMAIN_FQDN"
|
|
|
|
|
|
for domain_user in $(cat $AD_DOMAIN-userlist);
|
|
do
|
|
ademail=$(ldapsearch -LLL\
|
|
-x -h $DOMAIN_CONTROLLER_FQDN \
|
|
-D "$AD_QUERY_USERNAME@$AD_DOMAIN_FQDN" \
|
|
-w $AD_QUERY_PASSWORD \
|
|
-b "cn=users,dc=$DCPART1,dc=$DCPART2,dc=$DCPART3" \
|
|
-s sub "(samAccountName=$domain_user)" mail|grep "mail\:" | awk -F ":" '{print $2}')
|
|
realname=$(ldapsearch -LLL\
|
|
-x -h $DOMAIN_CONTROLLER_FQDN \
|
|
-D "$AD_QUERY_USERNAME@$AD_DOMAIN_FQDN" \
|
|
-w $AD_QUERY_PASSWORD \
|
|
-b "cn=users,dc=$DCPART1,dc=$DCPART2,dc=$DCPART3" \
|
|
-s sub "(samAccountName=$domain_user)" name|grep "name\:" |awk -F ":" '{print $2}')
|
|
adname=$(ldapsearch -LLL\
|
|
-x -h $DOMAIN_CONTROLLER_FQDN \
|
|
-D "$AD_QUERY_USERNAME@$AD_DOMAIN_FQDN" \
|
|
-w $AD_QUERY_PASSWORD \
|
|
-b "cn=users,dc=$DCPART1,dc=$DCPART2,dc=$DCPART3" \
|
|
-s sub "(samAccountName=$domain_user)" uid|grep "uid\:" |awk -F ":" '{print $2}')
|
|
echo "INSERT INTO users (username, authMethod, password, groups, role, real_name, email, domainUser) VALUES ('$adname', 3, NULL, '{\"4\":\"4\"}', 'User', '$realname', '$ademail', 0);"
|
|
done
|