From 2a08de6115e9ec635ddfd3944dd23577ed84667e Mon Sep 17 00:00:00 2001 From: Lutchy Horace Date: Wed, 17 Mar 2021 17:47:19 -0400 Subject: [PATCH 1/5] Initial support for --donotredirect --- bootstrap.sh | 11 +++++--- createVhosts.sh | 69 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index bb1db77..ac595d3 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -26,13 +26,18 @@ function warn function validate_host { + local _ret=0 + echo "$1" | grep -P '^(http|https):\/\/(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])(:[0-9]+)?$' > /dev/null 2>&1 if [ $? -eq 0 ]; then debug "Checking host is resolvable: $1" - # The remote servers may sometimes have self-signed certs - curl --insecure $1 > /dev/null 2>&1 + # Add --insecure becase remote servers may sometimes have self-signed certs + if ! curl --insecure $1 > /dev/null 2>&1; then + _ret=1 + debug "Host '$1' is not resolvable!" + fi fi - return $? + return $_ret } function validate_ip diff --git a/createVhosts.sh b/createVhosts.sh index 8b725c4..c3461cc 100755 --- a/createVhosts.sh +++ b/createVhosts.sh @@ -2,7 +2,6 @@ # # Create Vhosts on VPS3 # -DEBUG=0 #set -e @@ -13,8 +12,9 @@ function usage echo " Domain to use when creating vhost" echo " --root /var/www/html" echo " Root directory of this vhost" - echo " --backend http://127.0.0.1:80" + echo " --backend http://127.0.0.1" echo " Hostname of the backend server to pass traffic to" + echo " Note: Do not specify a port" echo " --listenip x.x.x.x" echo " IP to bind to when listening" echo " --desc x.x.x.x" @@ -48,10 +48,7 @@ else exit 1 fi -# gain priviledges -become "$@" - -OPTS=$(getopt -o h -l domain:,root:,backend:,listenip:,desc: -n 'createVhosts' -- "$@") +OPTS=$(getopt -o h -l domain:,root:,backend:,listenip:,desc:,donotredirect -n 'createVhosts' -- "$@") if [ "$?" -gt '0' ]; then echo 'Failed to set command line arguments' exit 1; @@ -60,6 +57,7 @@ fi eval set -- "$OPTS" _domain=false +_donotredirect=false _root="" _backend="" _listenip="" @@ -80,6 +78,9 @@ while true; do --desc ) _desc=$2 shift ;; + --donotredirect ) + _donotredirect=true + shift ;; -h | --help ) usage; shift ;; -- ) shift; break ;; * ) shift;; @@ -101,16 +102,48 @@ if test -n "$_root"; then _rootpath="root $_root;" fi +_check_host=success +_locationblock_http="" +_locationblock_https="" if test -n "$_backend"; then - echo "Verifying backend..." - if ! validate_host $_backend; then - err "Invalid hostname: $_backend. Not resolvable!" - fi -_locationblock=$(cat <<- EOF - proxy_pass $_backend; + echo "Verifying backend(s)..." + _https_backend=$(echo $_backend | sed 's/http/https/') + if validate_host $_https_backend:443; then + +#<<<<< Date: Wed, 17 Mar 2021 17:59:23 -0400 Subject: [PATCH 2/5] Restored become, woops --- createVhosts.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/createVhosts.sh b/createVhosts.sh index c3461cc..1e43c00 100755 --- a/createVhosts.sh +++ b/createVhosts.sh @@ -48,6 +48,9 @@ else exit 1 fi +# gain priviledges +become "$@" + OPTS=$(getopt -o h -l domain:,root:,backend:,listenip:,desc:,donotredirect -n 'createVhosts' -- "$@") if [ "$?" -gt '0' ]; then echo 'Failed to set command line arguments' From 7104e0aac9f570b00b7e6b7670f8929dd6882462 Mon Sep 17 00:00:00 2001 From: Lutchy Horace Date: Wed, 17 Mar 2021 18:12:14 -0400 Subject: [PATCH 3/5] Don't display a message if root it's not defined --- createVhosts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/createVhosts.sh b/createVhosts.sh index 1e43c00..e022c61 100755 --- a/createVhosts.sh +++ b/createVhosts.sh @@ -94,8 +94,8 @@ if [[ $_domain = false ]]; then err "You must set domain" fi -echo -n "Checking if $_root exists?" if test -n "$_root"; then + echo -n "Checking if $_root exists?" if ! test -d $_root; then echo " Creating..." mkdir -p $_root From 50b39d006b102c405ca85644cba06e446fbcad8d Mon Sep 17 00:00:00 2001 From: Lutchy Horace Date: Wed, 17 Mar 2021 18:15:24 -0400 Subject: [PATCH 4/5] Add a curl timeout --- bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.sh b/bootstrap.sh index e27d277..83952f3 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -32,7 +32,7 @@ function validate_host if [ $? -eq 0 ]; then debug "Checking host is resolvable: $1" # Add --insecure becase remote servers may sometimes have self-signed certs - if ! curl --insecure $1 > /dev/null 2>&1; then + if ! curl --insecure --max-time 5.5 $1 > /dev/null 2>&1; then _ret=1 debug "Host '$1' is not resolvable!" fi From acf0d83730cdfde0af2677d6faded66b4c926b95 Mon Sep 17 00:00:00 2001 From: Lutchy Horace Date: Wed, 17 Mar 2021 18:25:33 -0400 Subject: [PATCH 5/5] Correct curl --max-time value --- bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.sh b/bootstrap.sh index 83952f3..62cf12a 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -32,7 +32,7 @@ function validate_host if [ $? -eq 0 ]; then debug "Checking host is resolvable: $1" # Add --insecure becase remote servers may sometimes have self-signed certs - if ! curl --insecure --max-time 5.5 $1 > /dev/null 2>&1; then + if ! curl --insecure --max-time 5 $1 > /dev/null 2>&1; then _ret=1 debug "Host '$1' is not resolvable!" fi