]> git.plutz.net Git - cgilite/commitdiff
detect https/http schema for invite links
authorPaul Hänsch <paul@plutz.net>
Wed, 18 May 2022 20:33:46 +0000 (22:33 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 18 May 2022 20:33:46 +0000 (22:33 +0200)
users.sh

index 254d61c91953e87e882e7c4efe957ef50d41b576..ca986cd6f737a00c78915379bfe83c3f14eba6d5 100755 (executable)
--- a/users.sh
+++ b/users.sh
@@ -16,6 +16,8 @@ MAILFROM="${MAILDOMAIN-noreply@${HTTP_HOST%:*}}"
 
 HTTP_HOST="$(HEADER Host)"
 
+[ "$HTTPS" ] && SCHEMA=https || SCHEMA=http
+
 # == FILE FORMAT ==
 # UID  UNAME   STATUS  EMAIL   PWSALT  PWHASH  EXPIRE  DEVICES FUTUREUSE
 #              (pending|active|deleted)
@@ -233,7 +235,7 @@ user_register(){
       REDIRECT "${_BASE}${PATH_INFO}#ERROR_EMAIL_EXISTS"
     elif new_user "$uid" status=pending email="$email" expire="$((_DATE + 86400))"; then
       debug "Sending Activation Link:" \
-            "https://${HTTP_HOST}${_BASE}${PATH_INFO}?user_confirm=${uid}+$(session_mac "$uid")"
+            "${SCHEMA}://${HTTP_HOST}${_BASE}${PATH_INFO}?user_confirm=${uid}+$(session_mac "$uid")"
       "$SENDMAIL" -t -f "$MAILFROM" <<-EOF
        From: ${MAILFROM}
        To: ${email}
@@ -243,7 +245,7 @@ user_register(){
 
        You can activate your account using this link:
 
-           https://${HTTP_HOST}${_BASE}${PATH_INFO}?user_confirm=${uid}+$(session_mac "$uid")
+           ${SCHEMA}://${HTTP_HOST}${_BASE}${PATH_INFO}?user_confirm=${uid}+$(session_mac "$uid")
 
        This registration link will expire after 24 hours.
 
@@ -295,7 +297,7 @@ user_invite(){
     REDIRECT "${_BASE}${PATH_INFO}#ERROR_EMAIL_EXISTS"
   elif new_user "$uid" status=pending email="$email" expire="$((_DATE + 86400))"; then
     debug "Sending Invitation Link:" \
-          "https://${HTTP_HOST}${_BASE}${PATH_INFO}?user_confirm=${uid}+$(session_mac "$uid")"
+          "${SCHEMA}://${HTTP_HOST}${_BASE}${PATH_INFO}?user_confirm=${uid}+$(session_mac "$uid")"
     "$SENDMAIL" -t -f "$MAILFROM" <<-EOF
        From: ${MAILFROM}
        To: ${email}
@@ -307,7 +309,7 @@ user_invite(){
 
        You can create your account using this link:
 
-           https://${HTTP_HOST}${_BASE}${PATH_INFO}?user_confirm=${uid}+$(session_mac "$uid")
+           ${SCHEMA}://${HTTP_HOST}${_BASE}${PATH_INFO}?user_confirm=${uid}+$(session_mac "$uid")
 
        This registration link will expire after 24 hours.
 
@@ -555,7 +557,7 @@ w_user_invite(){
     new_user "$uid" status=pending email="$email" expire="$((_DATE + 86400))"
     cat <<-EOF
         [p An anonymous user account has been set up. Send the following link to the intended user, so they may claim their account. The link will remain valid for 24 hours.]
-        [p . $(HTML "https://${HTTP_HOST}${_BASE}${PATH_INFO}?user_confirm=${uid}+$(session_mac "$uid")" |debug)]
+        [p . $(HTML "${SCHEMA}://${HTTP_HOST}${_BASE}${PATH_INFO}?user_confirm=${uid}+$(session_mac "$uid")" |debug)]
 
         [p [a href="#" . Set up another account]]
        EOF