Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d09beaa8 authored by Felix Ableitner's avatar Felix Ableitner
Browse files

Use cleaner method for urlencode in generate-signup-link.sh

parent 75f42ac8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ install-deps:
      - gnupg2
      - pass
      - certbot
      - jq
    - require:
      - upgrade-all

+0 −28
Original line number Diff line number Diff line
@@ -37,31 +37,3 @@ SMTP_PW=$(grep ^SMTP_PW= "$ENVFILE" | awk -F= '{ print $NF }')
SMTP_HOST=$(grep ^SMTP_HOST= "$ENVFILE" | awk -F= '{ print $NF }')

MYSQL_ROOT_PASSWORD=$(grep ^MYSQL_ROOT_PASSWORD= "$ENVFILE" | awk -F= '{ print $NF }')

# the encoding/decoding is taken from here: https://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command/10660730#10660730
urlencode() {
  local string="${1}"
  local strlen=${#string}
  local encoded=""
  local pos c o

  for (( pos=0 ; pos<strlen ; pos++ )); do
     c=${string:$pos:1}
     case "$c" in
        [-_.~a-zA-Z0-9] ) o="${c}" ;;
        * )               printf -v o '%%%02x' "'$c"
     esac
     encoded+="${o}"
  done
  echo "${encoded}"    # You can either set a return variable (FASTER)
}

urldecode() {
  # This is perhaps a risky gambit, but since all escape characters must be
  # encoded, we can replace %NN with \xNN and pass the lot to printf -b, which
  # will decode hex for us

  printf -v REPLY '%b' "${1//%/\\x}" # You can either set a return variable (FASTER)

  echo "${REPLY}"  #+or echo the result (EASIER)... or both... :p
}
+2 −1
Original line number Diff line number Diff line
@@ -21,7 +21,8 @@ fi

AUTH_SECRET=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
echo "$EMAIL:$AUTH_SECRET" >> /mnt/repo-base/volumes/accounts/auth.file
SIGNUP_URL="https://welcome.$DOMAIN/?authmail=$(urlencode "$EMAIL")&authsecret=$AUTH_SECRET"
ENCODED_EMAIL=$(jq -nr --arg v "$EMAIL" '$v|@uri')
SIGNUP_URL="https://welcome.$DOMAIN/?authmail=$ENCODED_EMAIL&authsecret=$AUTH_SECRET"
echo "The new user can sign up now at $SIGNUP_URL"

echo -e "to:$EMAIL