Skip to content

Commit ec32653

Browse files
authored
Add email validation and hostname check (hestiacp#2216)
1 parent d5f0028 commit ec32653

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

install/hst-install-debian.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ validate_hostname () {
180180
fi
181181
}
182182

183+
validate_email (){
184+
if [[ ! "$email" =~ ^[A-Za-z0-9._%+-]+@[[:alnum:].-]+\.[A-Za-z]{2,63}$ ]] ; then
185+
# Email invalid
186+
return 0
187+
else
188+
# Email valid
189+
return 1
190+
fi
191+
}
192+
183193

184194
#----------------------------------------------------------#
185195
# Verifications #
@@ -586,7 +596,15 @@ if [ "$interactive" = 'yes' ]; then
586596

587597
# Asking for contact email
588598
if [ -z "$email" ]; then
599+
while validate_email; do
600+
echo -e "\nPlease use a valid emailadress (ex. info@domain.tld)."
589601
read -p 'Please enter admin email address: ' email
602+
done
603+
else
604+
if validate_email; then
605+
echo "Please use a valid emailadress (ex. info@domain.tld)."
606+
exit 1
607+
fi
590608
fi
591609

592610
# Asking to set FQDN hostname
@@ -630,6 +648,10 @@ if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
630648
echo "127.0.0.1 $servername" >> /etc/hosts
631649
fi
632650

651+
if [ -z $(grep -i "$servername" /etc/hosts) ]; then
652+
echo "127.0.0.1 $servername" >> /etc/hosts
653+
fi
654+
633655
# Set email if it wasn't set
634656
if [ -z "$email" ]; then
635657
email="admin@$servername"

install/hst-install-ubuntu.sh

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ validate_hostname () {
161161
fi
162162
}
163163

164+
validate_email (){
165+
if [[ ! "$email" =~ ^[A-Za-z0-9._%+-]+@[[:alnum:].-]+\.[A-Za-z]{2,63}$ ]] ; then
166+
# Email invalid
167+
return 0
168+
else
169+
# Email valid
170+
return 1
171+
fi
172+
}
164173

165174
#----------------------------------------------------------#
166175
# Verifications #
@@ -557,11 +566,19 @@ if [ "$interactive" = 'yes' ]; then
557566
exit 1
558567
fi
559568

560-
# Asking for contact email
561-
if [ -z "$email" ]; then
562-
read -p 'Please enter admin email address: ' email
569+
# Asking for contact email
570+
if [ -z "$email" ]; then
571+
while validate_email; do
572+
echo -e "\nPlease use a valid emailadress (ex. info@domain.tld)."
573+
read -p 'Please enter admin email address: ' email
574+
done
575+
else
576+
if validate_email; then
577+
echo "Please use a valid emailadress (ex. info@domain.tld)."
578+
exit 1
563579
fi
564-
580+
fi
581+
565582
# Asking to set FQDN hostname
566583
if [ -z "$servername" ]; then
567584
# Ask and validate FQDN hostname.
@@ -603,6 +620,10 @@ if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
603620
echo "127.0.0.1 $servername" >> /etc/hosts
604621
fi
605622

623+
if [ -z $(grep -i "$servername" /etc/hosts) ]; then
624+
echo "127.0.0.1 $servername" >> /etc/hosts
625+
fi
626+
606627
# Set email if it wasn't set
607628
if [ -z "$email" ]; then
608629
email="admin@$servername"

0 commit comments

Comments
 (0)