Domain name validation in interactive installer

This commit is contained in:
Bob Mottram 2015-01-25 20:39:00 +00:00
parent 129e147b32
commit 3de54edf47
1 changed files with 65 additions and 17 deletions

View File

@ -437,6 +437,19 @@ function interactive_configuration_remote_backups {
fi
}
# test a domain name to see if it's valid
function validate_domain_name {
# count the number of dots in the domain name
dots=${TEST_DOMAIN_NAME//[^.]}
no_of_dots=${#dots}
if (( $no_of_dots > 2 )); then
TEST_DOMAIN_NAME="The domain $TEST_DOMAIN_NAME has too many subdomains. It should be of the type x.y.z or y.z"
fi
if (( $no_of_dots == 0 )); then
TEST_DOMAIN_NAME="The domain $TEST_DOMAIN_NAME has no top level domain. It should be of the type x.y.z or y.z"
fi
}
function save_configuration_file {
echo "MY_USERNAME=$MY_USERNAME" > freedombone.cfg
echo "DOMAIN_NAME=$DOMAIN_NAME" >> freedombone.cfg
@ -662,8 +675,8 @@ function interactive_configuration {
dialog --backtitle "Freedombone Configuration" \
--title "Wiki Configuration" \
--form "\nPlease enter your wiki details:" 11 55 3 \
"Title:" 1 1 "My Wiki" 1 16 16 15 \
"Domain:" 2 1 "" 2 16 16 15 \
"Title:" 1 1 "$WIKI_TITLE" 1 16 25 40 \
"Domain:" 2 1 "$WIKI_DOMAIN_NAME" 2 16 25 40 \
2> $data
sel=$?
case $sel in
@ -673,8 +686,15 @@ function interactive_configuration {
WIKI_TITLE=$(cat $data | sed -n 1p)
WIKI_DOMAIN_NAME=$(cat $data | sed -n 2p)
if [ $WIKI_DOMAIN_NAME ]; then
if [ ! $DOMAIN_NAME ]; then
DOMAIN_NAME=$WIKI_DOMAIN_NAME
TEST_DOMAIN_NAME=$WIKI_DOMAIN_NAME
validate_domain_name
if [[ $TEST_DOMAIN_NAME != $WIKI_DOMAIN_NAME ]]; then
WIKI_DOMAIN_NAME=
dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
if [ ! $DOMAIN_NAME ]; then
DOMAIN_NAME=$WIKI_DOMAIN_NAME
fi
fi
fi
done
@ -688,8 +708,8 @@ function interactive_configuration {
dialog --backtitle "Freedombone Configuration" \
--title "Blog Configuration" \
--form "\nPlease enter your blog details:" 11 55 3 \
"Title:" 1 1 "My Blog" 1 16 16 15 \
"Domain:" 2 1 "" 2 16 16 15 \
"Title:" 1 1 "My Blog" 1 16 25 30 \
"Domain:" 2 1 "" 2 16 25 30 \
2> $data
sel=$?
case $sel in
@ -702,8 +722,15 @@ function interactive_configuration {
if [[ $FULLBLOG_DOMAIN_NAME == "$WIKI_DOMAIN_NAME" ]]; then
FULLBLOG_DOMAIN_NAME=""
fi
if [ ! $DOMAIN_NAME ]; then
DOMAIN_NAME=$FULLBLOG_DOMAIN_NAME
TEST_DOMAIN_NAME=$FULLBLOG_DOMAIN_NAME
validate_domain_name
if [[ $TEST_DOMAIN_NAME != $FULLBLOG_DOMAIN_NAME ]]; then
FULLBLOG_DOMAIN_NAME=
dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
if [ ! $DOMAIN_NAME ]; then
DOMAIN_NAME=$FULLBLOG_DOMAIN_NAME
fi
fi
fi
done
@ -717,7 +744,7 @@ function interactive_configuration {
dialog --backtitle "Freedombone Configuration" \
--title "Owncloud Configuration" \
--form "\nPlease enter your Owncloud details:" 11 55 3 \
"Domain:" 1 1 "" 1 16 16 15 \
"Domain:" 1 1 "" 1 16 25 30 \
2> $data
sel=$?
case $sel in
@ -726,8 +753,15 @@ function interactive_configuration {
esac
OWNCLOUD_DOMAIN_NAME=$(cat $data | sed -n 1p)
if [ $OWNCLOUD_DOMAIN_NAME ]; then
if [ ! $DOMAIN_NAME ]; then
DOMAIN_NAME=$OWNCLOUD_DOMAIN_NAME
TEST_DOMAIN_NAME=$OWNCLOUD_DOMAIN_NAME
validate_domain_name
if [[ $TEST_DOMAIN_NAME != $OWNCLOUD_DOMAIN_NAME ]]; then
OWNCLOUD_DOMAIN_NAME=
dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
if [ ! $DOMAIN_NAME ]; then
DOMAIN_NAME=$OWNCLOUD_DOMAIN_NAME
fi
fi
fi
done
@ -741,7 +775,7 @@ function interactive_configuration {
dialog --backtitle "Freedombone Configuration" \
--title "RedMatrix Configuration" \
--form "\nPlease enter your RedMatrix details:" 11 55 3 \
"Domain:" 1 1 "" 1 16 16 15 \
"Domain:" 1 1 "" 1 16 25 30 \
2> $data
sel=$?
case $sel in
@ -750,8 +784,15 @@ function interactive_configuration {
esac
REDMATRIX_DOMAIN_NAME=$(cat $data | sed -n 1p)
if [ $REDMATRIX_DOMAIN_NAME ]; then
if [ ! $DOMAIN_NAME ]; then
DOMAIN_NAME=$REDMATRIX_DOMAIN_NAME
TEST_DOMAIN_NAME=$REDMATRIX_DOMAIN_NAME
validate_domain_name
if [[ $TEST_DOMAIN_NAME != $REDMATRIX_DOMAIN_NAME ]]; then
REDMATRIX_DOMAIN_NAME=
dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
if [ ! $DOMAIN_NAME ]; then
DOMAIN_NAME=$REDMATRIX_DOMAIN_NAME
fi
fi
fi
done
@ -765,7 +806,7 @@ function interactive_configuration {
dialog --backtitle "Freedombone Configuration" \
--title "Microblog Configuration" \
--form "\nPlease enter your Microblog details:" 11 55 3 \
"Domain:" 1 1 "" 1 16 16 15 \
"Domain:" 1 1 "" 1 16 25 30 \
2> $data
sel=$?
case $sel in
@ -777,8 +818,15 @@ function interactive_configuration {
if [[ $MICROBLOG_DOMAIN_NAME == "$REDMATRIX_DOMAIN_NAME" ]]; then
MICROBLOG_DOMAIN_NAME=""
fi
if [ ! $DOMAIN_NAME ]; then
DOMAIN_NAME=$MICROBLOG_DOMAIN_NAME
TEST_DOMAIN_NAME=$MICROBLOG_DOMAIN_NAME
validate_domain_name
if [[ $TEST_DOMAIN_NAME != $MICROBLOG_DOMAIN_NAME ]]; then
MICROBLOG_DOMAIN_NAME=
dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
if [ ! $DOMAIN_NAME ]; then
DOMAIN_NAME=$MICROBLOG_DOMAIN_NAME
fi
fi
fi
done