Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: encode URL in the bash client #521

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions client/plik.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ set -e
green='\e[0;32m'
endColor='\e[0m'
function jsonValue() {
KEY=$1
sed -e "s/,/\n/g" | sed -e "s/[\"{}]//g" | grep $KEY | cut -d ":" -f2-
echo $(cat | sed -n "s/.*\"$1\":\"\([^\"]*\)\".*/\1/p")
}

function qecho(){
Expand All @@ -34,6 +33,23 @@ function setTtl() {
return
}

function rawurlencode() {
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}" ;;
* ) o=$(printf "$c" | hexdump -e '/1 "%02X\n"' | tr '\n' '%' | sed 's/^/%/; s/.$//')
esac
encoded+="${o}"
done
echo "${encoded}"
}

#
## Vars
#
Expand All @@ -44,7 +60,7 @@ PASSPHRASE=""
ARCHIVE=false
ONESHOT=false
REMOVABLE=false
TTL=0
TTL=604800 # a week

#
## Read ~/.plikrc file
Expand Down Expand Up @@ -223,24 +239,25 @@ do
FILE_URL="$DOWNLOAD_DOMAIN/file/$UPLOAD_ID/$FILE_ID/$FILE_NAME"

# Compute get command
COMMAND="curl -s $FILE_URL"
REPLY=$(rawurlencode "$FILE_URL")
COMMAND="curl -s '$REPLY'"

if [ "$SECURE" == true ]; then
COMMAND+=" | openssl aes-256-cbc -d -pass \"pass:$PASSPHRASE\""
fi

if [ "$ARCHIVE" == true ]; then
COMMAND+=" | tar zxvf -"
COMMAND+=" | tar zxf -"
else
COMMAND+=" > $FILE_NAME"
COMMAND+=" > '$FILE_NAME'"
fi

# Output
if [ "$QUIET" == true ]; then
echo "$FILE_URL"
echo "$REPLY"
else
echo "$COMMAND"
fi
echo -n "$PLIK_URL/#/?id=$UPLOAD_ID"
done
qecho

Loading