#!/bin/bash # Zielpfad für das Full-Chain-Zertifikat FULLCHAIN_CERT="/tmp/fullchain.crt" HOST_FQDN=$(hostname -f) HOST_NORMAL=$(hostname -s) DOMAIN=$(hostname -d) # Name der Zertifikatsdateien ROOT_CERT="CERT_HEIMLAN_RootCA.crt" SUBCA_CERT="CERT_HEIMLAN_SubCA.crt" SERVER_CERT="CERT_${HOST_FQDN}.crt" SERVER_KEY="KEY_${HOST_FQDN}.pem" LDAP_PASS="P@SSW0RD" # LDAP-Serverinformationen für mehrere Domänen (LDAPS) LDAP_SERVERS=( "HEIM.LAN|ldaps://dc.heim.lan|dc=heim,dc=lan|CN=Administrator,CN=Users,DC=heim,DC=lan|${LDAP_PASS}" "IOT.HEIM.LAN|ldaps://ipa.iot.heim.lan|dc=iot,dc=heim,dc=lan|uid=admin,cn=users,cn=accounts,dc=iot,dc=heim,dc=lan|${LDAP_PASS}" ) colormsg() { echo -e "\033[0;36m$1\033[0m" } # Funktion zum Kopieren der Zertifikate in die richtigen Pfade je nach Derivat und Typ copy_certificates() { echo "Kopieren der Zertifikate in die richtigen Pfade..." # Betriebssystem erkennen if grep -q -i "ubuntu\|debian" /etc/os-release; then distro="Debian" elif grep -q -i "centos\|rhel\|red hat" /etc/os-release; then distro="CentOS" else echo "Nicht unterstütztes Betriebssystem." exit 1 fi case $distro in Debian) SSL_DIR="/etc/nginx/ssl" TMP="/usr/local/share/ca-certificates" KEY="/etc/ssl/private" echo -e "\033[0;32mEforderliche Pakete werden installiert...\033[0m" sudo apt update sudo apt install -y nginx openldap-clients wget gnupg2 ca-certificates lsb-release build-essential libpcre3 libpcre3-dev zlib1g-dev libssl-dev git echo "***************** Sie sind auf einen Debian \ Ubuntu System...... ******************************************" ;; CentOS) SSL_DIR="/etc/nginx/ssl" TMP="/etc/pki/ca-trust/source/anchors" KEY="/etc/pki/tls/private" echo -e "\033[0;32mEforderliche Pakete werden installiert...\033[0m" subscription-manager repos --enable codeready-builder-for-rhel-8-$(arch)-rpms yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm sudo dnf install -y epel-release nginx openldap-clients openldap-servers openldap-devel pcre pcre-devel zlib zlib-devel openssl openssl-devel git gcc sudo yum groupinstall -y "Development Tools" echo "***************** Sie sind auf einen Red Hat \ CentOS System...... *****************************************" ;; esac echo -e "\033[0;32mZusätzliche Pakete von GIT werden heruntergeladen und installiert...\033[0m" cd /usr/local/src sudo wget https://nginx.org/download/nginx-1.26.1.tar.gz sudo tar -zxvf nginx-1.26.1.tar.gz sudo git clone https://github.com/kvspb/nginx-auth-ldap.git echo -e "\033[0;32mNginx mit LDAP-Modul kompilieren und installieren...\033[0m" cd nginx-1.26.1 sudo ./configure --add-module=/usr/local/src/nginx-auth-ldap sudo make sudo make install # Verzeichnisse erstellen, falls nicht vorhanden sudo mkdir -p $SSL_DIR # Zertifikate kopieren sudo cp "$TMP/$ROOT_CERT" "$SSL_DIR/$ROOT_CERT" sudo cp "$TMP/$SUBCA_CERT" "$SSL_DIR/$SUBCA_CERT" sudo cp "$TMP/${SERVER_CERT}" "$SSL_DIR/${SERVER_CERT}" sudo cp "$KEY/$SERVER_KEY" "$SSL_DIR/${SERVER_KEY}" echo "Zertifikate wurden nach $SSL_DIR kopiert." } # Funktion zur Erstellung der LDAP-Serverkonfiguration create_ldap_config() { echo "Erstellen der LDAP-Konfigurationsdatei..." LDAP_CONF="/etc/nginx/conf.d/ldap.conf" sudo tee $LDAP_CONF > /dev/null < /dev/null <