<commit_before><commit_msg>installers LDAP server<commit_after>!#/bin/bash
#this shell script will install and configure LDAP
#remember that all configuration will be preset with my domains and user

#installing all packages
yum -y install openldap-servers openldap-clients
yum -y install httpd epel-release phpldapadmin

#enabling all services
systemctl enable slapd.service
systemctl start slapd.service
systemctl enable httpd.service
systemctl start httpd.service

#modify the access in phpldapadmin configuration
sed -i 's,Require local,#Require local\n    Require all granted,g' /etc/httpd/conf.d/phpldapadmin.conf

#restarting HTTP service
systemctl restart httpd.service

#notify the system
setsebool -P httpd_can_connect_ldap on

#creating a directory to store .ldif files
mkdir ~/LDAP_config

#creatin a SSHA password for LDAP root
password=<PASSWORD>
passw=$(slappasswd -s $password -h {SSHA})

#creating .ldif files
sh -c 'cat > ~/LDAP_config/db.ldif' << EF
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=NTI,dc=local

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=admin,dc=NTI,dc=local

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: $passw
EF

sh -c 'cat > ~/LDAP_config/monitor.ldif' << EF
dn: olcDatabase={1}monitor,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external, cn=auth" read by dn.base="cn=admin,dc=NTI,dc=local" read by * none
EF

#creating a certification file
sh -c 'cat > ~/LDAP_config/certs.ldif' << EF
dn: cn=config
changetype: modify
replace: olcTLSCertificateFile
olcTLSCertificateFile: /etc/openldap/certs/NTIcert.pem

dn: cn=config
changetype: modify
replace: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /etc/openldap/certs/NTIkey.pem
EF

sh -c 'cat > ~/LDAP_config/base.ldif' << EF
dn: dc=NTI,dc=local
dc: NTI
objectClass: top
objectClass: domain

dn: cn=admin,dc=NTI,dc=local
objectClass: organizationalRole
cn: admin
description: LDAP Manager

dn: ou=ITPeople,dc=NTI,dc=local
objectClass: organizationalUnit
ou: ITPeople

dn: ou=ITGroup,dc=NTI,dc=local
objectClass: organizationalUnit
ou: ITGroup
EF

#creating LDAP certificate
openssl req -new -x509 -nodes -out /etc/openldap/certs/NTIcert.pem -keyout /etc/openldap/certs/NTIkey.pem -days 365 -subj "/C=US/ST=WA/L=Seattle/O=ITcor/OU=ITinfraestructure/CN=server.NTI.local"

#change the permissions to LDAP
chown -R ldap:ldap /etc/openldap/certs/*.pem

#copy the sample database configuration
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap:ldap /var/lib/ldap/*

#set up LDAP server
ldapmodify -Y EXTERNAL  -H ldapi:/// -f ~/LDAP_config/db.ldif
ldapmodify -Y EXTERNAL  -H ldapi:/// -f ~/LDAP_config/monitor.ldif
ldapmodify -Y EXTERNAL  -H ldapi:/// -f ~/LDAP_config/certs.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif 
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
ldapadd -x -w $password -D "cn=admin,dc=NTI,dc=local" -f ~/LDAP_config/base.ldif

#verify the configuration
slaptest -u

{'fraction_non_alphanumeric': 0.11569478908188585, 'fraction_numerical': 0.004032258064516129, 'mean_word_length': 5.190019193857966, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1158379', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1250, 'n_words': 314}