diff --git a/dapostinstall.sh b/dapostinstall.sh index a643277..e5f9a0c 100755 --- a/dapostinstall.sh +++ b/dapostinstall.sh @@ -12,6 +12,7 @@ LOG_FILE=/var/log/dapostinstall.log HTLINK="https://ht.zenadmin.pl" MIN_PASSWORD_LENGTH=18 MAX_PASSWORD_LENGTH=24 +ITERATION_LIMIT=100 exec > >(tee -ia "$LOG_FILE") 2>&1 cd $DAPOSTINSTALL_DIR yum -y install epel-release @@ -19,7 +20,7 @@ yum -y install htop wget rsync nano mc ncdu borgbackup screen net-tools htop lib cp daupdate.sh /opt chmod 700 /opt/daupdate.sh cd /opt/ -/optdaupdate.sh update +/opt/daupdate.sh update cd $DAPOSTINSTALL_DIR clear cd $DAPOSTINSTALL_DIR @@ -143,9 +144,8 @@ EOT echo "Ustawienie kluczy logowania do DirectAdmina i kluczy SSH hitme" -cd /opt -sh daupdate.sh klucze -sh daupdate keyput +daupdate.sh klucze +daupdate keyput cd $DAPOSTINSTALL_DIR echo "Instalacja Modsecurity i regułek malware experts" @@ -365,13 +365,17 @@ chmod 755 da_cli.sh echo "Generowanie hasla DirectAdmin" +count=0 + DA_ADMINPASS=$( while true; do - base_part=$(tr -dc '[:alnum:]' < /dev/urandom | tr -d 'oO0l1I' | fold -w "$((RANDOM % (MAX_PASSWORD_LENGTH - MIN_PASSWORD_LENGTH) + MIN_PASSWORD_LENGTH))" | head -n1) - special_char=$(tr -dc '[:graph:]' < /dev/urandom | tr -d '#oO0l1I' | fold -w 1 | head -n1) + ((count++)) + [ "$count" -gt "$ITERATION_LIMIT" ] && { echo "Błąd: przekroczono limit iteracji generowania hasła" >&2; exit 1; } + base_part=$(tr -dc '[:alnum:]' < /dev/urandom | tr -d 'oO0l1I' | fold -w "$((RANDOM % (MAX_PASSWORD_LENGTH - MIN_PASSWORD_LENGTH + 1) + MIN_PASSWORD_LENGTH))" | head -n1) + special_char=$(tr -dc '[:graph:]' < /dev/urandom | tr -d '#|oO0l1I' | fold -w 1 | head -n1) special_index=$((RANDOM % ${#base_part})) password="${base_part:0:special_index}${special_char}${base_part:special_index}" - if echo "$password" | grep -qE '[[:digit:]]' && echo "$password" | grep -qE '[[:upper:]]' && echo "$password" | grep -qE '[^[:alnum:]]'; then + if echo "$password" | grep -qP '^(?=.*[[:digit:]])(?=.*[[:upper:]])(?=.*[^[:alnum:]]).+$'; then echo "$password" break fi