|
|
@@ -1,9 +1,8 @@
|
|
|
#!/bin/bash
|
|
|
-# info: add/remove HSTS support from a domain
|
|
|
-# options: USER DOMAIN STATUS
|
|
|
+# info: Adding hsts to a domain
|
|
|
+# options: USER DOMAIN
|
|
|
#
|
|
|
-# This function will enable or disable HSTS (HTTP Strict Transport Security)
|
|
|
-# for a web domain.
|
|
|
+# The function enables HSTS for the requested domain.
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
@@ -13,14 +12,12 @@
|
|
|
# Argument definition
|
|
|
user=$1
|
|
|
domain=$2
|
|
|
-domain_idn=$2
|
|
|
-status=$3
|
|
|
|
|
|
# Includes
|
|
|
source $HESTIA/func/main.sh
|
|
|
-source $HESTIA/func/domain.sh
|
|
|
source $HESTIA/conf/hestia.conf
|
|
|
|
|
|
+
|
|
|
#----------------------------------------------------------#
|
|
|
# Verifications #
|
|
|
#----------------------------------------------------------#
|
|
|
@@ -32,6 +29,7 @@ is_object_unsuspended 'user' 'USER' "$user"
|
|
|
is_object_valid 'web' 'DOMAIN' "$domain"
|
|
|
is_object_unsuspended 'web' 'DOMAIN' "$domain"
|
|
|
|
|
|
+
|
|
|
#----------------------------------------------------------#
|
|
|
# Action #
|
|
|
#----------------------------------------------------------#
|
|
|
@@ -52,18 +50,9 @@ else
|
|
|
hstsconf="$HOMEDIR/$user/conf/web/$domain/$PROXY_SYSTEM.hsts.conf"
|
|
|
fi
|
|
|
|
|
|
-if [ "$status" = "on" ]; then
|
|
|
- echo 'add_header Strict-Transport-Security "max-age=15768000;" always;' > $hstsconf
|
|
|
- nginx -s reload
|
|
|
- echo "HTTP Strict Transport Security (HSTS) turned on for $domain."
|
|
|
-elif [ "$status" = "off" ]; then
|
|
|
- rm -f $hstsconf
|
|
|
- nginx -s reload
|
|
|
- echo "HTTP Strict Transport Security (HSTS) turned off for $domain."
|
|
|
-else
|
|
|
- echo "Error: Invalid mode specified."
|
|
|
- echo "Usage: v-change-web-domain-hsts USER DOMAIN [ON / OFF]"
|
|
|
-fi
|
|
|
+echo 'add_header Strict-Transport-Security "max-age=15768000;" always;' > $hstsconf
|
|
|
+echo "HTTP Strict Transport Security (HSTS) turned on for $domain."
|
|
|
+
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
# Hestia #
|
|
|
@@ -73,4 +62,12 @@ fi
|
|
|
log_history "Turned HTTP Strict Transport Security $status for $domain."
|
|
|
log_event "$OK" "$ARGUMENTS"
|
|
|
|
|
|
+# Restart web server
|
|
|
+$BIN/v-restart-web
|
|
|
+check_result $? "Web restart failed" > /dev/null
|
|
|
+
|
|
|
+# Restart proxy
|
|
|
+$BIN/v-restart-proxy
|
|
|
+check_result $? "Proxy restart failed" > /dev/null
|
|
|
+
|
|
|
exit
|